Coverage for test/test_scenario_forest.py: 100%
50 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-08-06 10:33 -0400
« prev ^ index » next coverage.py v7.2.7, created at 2023-08-06 10:33 -0400
1"""Test the ScenarioForest class"""
3import os
4import filecmp
5import pdb
7import pytest
9import manyworlds as mw
11@pytest.fixture(scope='session', autouse=True)
12def clear_out_directory():
13 """Delete all files in test/out"""
14 folder = os.path.dirname(os.path.realpath(__file__)) + '/out'
15 for filename in os.listdir(folder):
16 if not filename == '.gitignore':
17 file_path = os.path.join(folder, filename)
18 os.unlink(file_path)
19 yield
21def test_parse():
22 """Test the structure of the forest graph after using the 'from_file' method"""
23 forest = mw.ScenarioForest.from_file('test/fixtures/scenarios_forest.feature')
24 assert len(forest.root_scenarios()) == 1
26 root_scenario = forest.find('View users')
27 assert root_scenario.name == 'View users'
28 assert root_scenario.level() == 1
29 assert len(root_scenario.ancestors()) == 0
30 assert len(root_scenario.prerequisites()) == 1
31 assert len(root_scenario.actions()) == 1
32 assert len(root_scenario.assertions()) == 1
33 data = root_scenario.prerequisites()[0].data
34 assert len(data) == 4
35 assert data[2]['Name'] == 'Connie'
36 assert data[2]['Status'] == 'Active'
38 leaf_scenario = forest.find('View users', 'Bulk operations', 'Select user', 'Select multiple users', 'Bulk deactivate users', 'Confirm bulk deactivation of users')
39 assert leaf_scenario.name == 'Confirm bulk deactivation of users'
40 assert leaf_scenario.level() == 6
41 assert len(leaf_scenario.ancestors()) == 5
42 assert len(leaf_scenario.prerequisites()) == 0
43 assert len(leaf_scenario.actions()) == 1
44 assert len(leaf_scenario.assertions()) == 2
46def test_flatten_strict():
47 """Test the 'flatten' method in 'strict' mode"""
48 forest = mw.ScenarioForest.from_file('test/fixtures/scenarios_forest.feature')
49 forest.flatten('test/out/scenarios_flat_strict.feature')
50 assert filecmp.cmp('test/out/scenarios_flat_strict.feature',
51 'test/fixtures/scenarios_flat_strict.feature')
53def test_flatten_strict_with_comments():
54 """Test the 'flatten' method in 'strict' mode with comments turned on"""
55 forest = mw.ScenarioForest.from_file('test/fixtures/scenarios_forest.feature')
56 forest.flatten('test/out/scenarios_flat_strict_with_comments.feature', comments=True)
57 assert filecmp.cmp('test/out/scenarios_flat_strict_with_comments.feature',
58 'test/fixtures/scenarios_flat_strict_with_comments.feature')
59def test_flatten_relaxed():
60 """Test the 'flatten' method in 'relaxed' mode"""
61 forest = mw.ScenarioForest.from_file('test/fixtures/scenarios_forest.feature')
62 forest.flatten('test/out/scenarios_flat_relaxed.feature', mode='relaxed')
63 assert filecmp.cmp('test/out/scenarios_flat_relaxed.feature',
64 'test/fixtures/scenarios_flat_relaxed.feature')
66def test_flatten_relaxed_with_comments():
67 """Test the 'flatten' method in 'relaxed' mode with comments turned on"""
68 forest = mw.ScenarioForest.from_file('test/fixtures/scenarios_forest.feature')
69 forest.flatten('test/out/scenarios_flat_relaxed_with_comments.feature', comments=True)
70 assert filecmp.cmp('test/out/scenarios_flat_relaxed_with_comments.feature',
71 'test/fixtures/scenarios_flat_relaxed_with_comments.feature')