Coverage for test/test_scenario_forest.py: 100%
55 statements
« prev ^ index » next coverage.py v7.3.0, created at 2023-08-25 16:44 +0200
« prev ^ index » next coverage.py v7.3.0, created at 2023-08-25 16:44 +0200
1"""Test the ScenarioForest class"""
3import os
4import filecmp
6import pytest
8import 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
22def test_find():
23 forest = mw.ScenarioForest.from_file("test/fixtures/in/scenario_forest.feature")
25 # Finds existing root scenario:
26 root_scenario = forest.find("View users")
27 assert type(root_scenario) == mw.scenario.Scenario
29 # Does not find anything if first name provided is not a root scenario:
30 root_scenario = forest.find("Select user")
31 assert root_scenario is None
33 # Finds existing non-root scenario
34 non_root_scenario = forest.find("View users", "Bulk operations", "Select user")
35 assert non_root_scenario is not None
37 # Does not find non-existing non-root scenario (path scenario missing)
38 non_root_scenario = forest.find("View users", "Select user")
39 assert non_root_scenario is None
42def test_parse():
43 """Test the structure of the forest graph after using the 'from_file' method"""
44 forest = mw.ScenarioForest.from_file("test/fixtures/in/scenario_forest.feature")
45 assert len(forest.root_scenarios()) == 1
47 # root scenario:
48 root_scenario = forest.find("View users")
49 assert root_scenario.name == "View users"
50 assert len(root_scenario.prerequisites()) == 1
51 assert len(root_scenario.actions()) == 1
52 assert len(root_scenario.assertions()) == 1
53 data = root_scenario.prerequisites()[0].data.to_list_of_dict()
54 assert len(data) == 4
55 assert data[2]["Name"] == "Connie"
56 assert data[2]["Status"] == "Active"
58 # leaf scenario:
59 leaf_scenario = forest.find(
60 "View users",
61 "Bulk operations",
62 "Select user",
63 "Select multiple users",
64 "Bulk deactivate users",
65 "Confirm bulk deactivation of users",
66 )
67 assert leaf_scenario.name == "Confirm bulk deactivation of users"
68 assert len(leaf_scenario.prerequisites()) == 0
69 assert len(leaf_scenario.actions()) == 1
70 assert len(leaf_scenario.assertions()) == 2
73def test_flatten_strict():
74 """Test the 'flatten' method in 'strict' mode"""
75 forest = mw.ScenarioForest.from_file("test/fixtures/in/scenario_forest.feature")
76 forest.flatten("test/out/scenarios_flat_strict.feature")
77 assert filecmp.cmp(
78 "test/out/scenarios_flat_strict.feature",
79 "test/fixtures/out/scenarios_flat_strict.feature",
80 )
83def test_flatten_strict_with_comments():
84 """Test the 'flatten' method in 'strict' mode with comments turned on"""
85 forest = mw.ScenarioForest.from_file("test/fixtures/in/scenario_forest.feature")
86 forest.flatten(
87 "test/out/scenarios_flat_strict_with_comments.feature", comments=True
88 )
89 assert filecmp.cmp(
90 "test/out/scenarios_flat_strict_with_comments.feature",
91 "test/fixtures/out/scenarios_flat_strict_with_comments.feature",
92 )
95def test_flatten_relaxed():
96 """Test the 'flatten' method in 'relaxed' mode"""
97 forest = mw.ScenarioForest.from_file("test/fixtures/in/scenario_forest.feature")
98 forest.flatten("test/out/scenarios_flat_relaxed.feature", mode="relaxed")
99 assert filecmp.cmp(
100 "test/out/scenarios_flat_relaxed.feature",
101 "test/fixtures/out/scenarios_flat_relaxed.feature",
102 )
105def test_organizational_scenarios():
106 """Test the correct output of organizational scenarios"""
107 forest = mw.ScenarioForest.from_file(
108 "test/fixtures/in/scenario_forest_with_organizational_scenarios.feature"
109 )
110 forest.flatten(
111 "test/out/scenarios_flat_strict_with_organizational_scenarios.feature",
112 mode="strict",
113 )
114 assert filecmp.cmp(
115 "test/out/scenarios_flat_strict_with_organizational_scenarios.feature",
116 "test/fixtures/out/scenarios_flat_strict_with_organizational_scenarios.feature",
117 )