|
1 | 1 | import unittest
|
2 | 2 | import shutil
|
| 3 | +import json |
3 | 4 | from pathlib import Path
|
4 |
| -from causal_testing.main import CausalTestingPaths |
| 5 | +from causal_testing.main import CausalTestingPaths, CausalTestingFramework |
5 | 6 |
|
6 | 7 |
|
7 | 8 | class TestCausalTestingPaths(unittest.TestCase):
|
@@ -35,3 +36,45 @@ def test_output_file_created(self):
|
35 | 36 | def tearDown(self):
|
36 | 37 | if self.output_path.parent.exists():
|
37 | 38 | shutil.rmtree(self.output_path.parent)
|
| 39 | + |
| 40 | + |
| 41 | +class TestCausalTestingFramework(unittest.TestCase): |
| 42 | + def setUp(self): |
| 43 | + self.dag_path = "tests/resources/data/dag.dot" |
| 44 | + self.data_paths = ["tests/resources/data/data.csv"] |
| 45 | + self.test_config_path = "tests/resources/data/tests.json" |
| 46 | + self.output_path = Path("results/results.json") |
| 47 | + |
| 48 | + def test_ctf(self): |
| 49 | + # Create paths object |
| 50 | + paths = CausalTestingPaths( |
| 51 | + dag_path=self.dag_path, |
| 52 | + data_paths=self.data_paths, |
| 53 | + test_config_path=self.test_config_path, |
| 54 | + output_path=self.output_path, |
| 55 | + ) |
| 56 | + |
| 57 | + # Create and setup framework |
| 58 | + framework = CausalTestingFramework(paths) |
| 59 | + framework.setup() |
| 60 | + |
| 61 | + # Load and run tests |
| 62 | + framework.load_tests() |
| 63 | + results = framework.run_tests() |
| 64 | + |
| 65 | + # Save results |
| 66 | + framework.save_results(results) |
| 67 | + |
| 68 | + with open(self.test_config_path, "r", encoding="utf-8") as f: |
| 69 | + test_configs = json.load(f) |
| 70 | + |
| 71 | + tests_passed = [ |
| 72 | + test_case.expected_causal_effect.apply(result) if result.test_value.type != "Error" else False |
| 73 | + for test_config, test_case, result in zip(test_configs["tests"], framework.test_cases, results) |
| 74 | + ] |
| 75 | + |
| 76 | + self.assertEqual(tests_passed, [True]) |
| 77 | + |
| 78 | + def tearDown(self): |
| 79 | + if self.output_path.parent.exists(): |
| 80 | + shutil.rmtree(self.output_path.parent) |
0 commit comments