|
8 | 8 |
|
9 | 9 | class MergerTest(unittest.TestCase): |
10 | 10 | def test_merger(self): |
11 | | - file1 = tempfile.NamedTemporaryFile("w") |
12 | | - json.dump( |
13 | | - { |
14 | | - "_pytest": "pytest", |
15 | | - "_pytest.__init__": "pytest", |
16 | | - "_pytest._argcomplete": "pytest", |
17 | | - "_pytest.config.argparsing": "pytest", |
18 | | - }, |
19 | | - file1, |
20 | | - ) |
21 | | - file1.flush() |
22 | | - file2 = tempfile.NamedTemporaryFile("w") |
23 | | - json.dump( |
24 | | - {"django_types": "django_types"}, |
25 | | - file2, |
26 | | - ) |
27 | | - file2.flush() |
28 | | - output_file = tempfile.NamedTemporaryFile("r") |
29 | | - |
30 | | - merge_modules_mappings( |
31 | | - [pathlib.Path(file1.name), pathlib.Path(file2.name)], |
32 | | - pathlib.Path(output_file.name), |
33 | | - ) |
34 | | - |
35 | | - self.assertEqual( |
36 | | - { |
37 | | - "_pytest": "pytest", |
38 | | - "_pytest.__init__": "pytest", |
39 | | - "_pytest._argcomplete": "pytest", |
40 | | - "_pytest.config.argparsing": "pytest", |
41 | | - "django_types": "django_types", |
42 | | - }, |
43 | | - json.load(output_file), |
44 | | - ) |
| 11 | + with tempfile.TemporaryDirectory() as tmpdir: |
| 12 | + d = pathlib.Path(tmpdir) |
| 13 | + path1 = d / "file1.json" |
| 14 | + path2 = d / "file2.json" |
| 15 | + output_path = d / "output.json" |
| 16 | + |
| 17 | + path1.write_text( |
| 18 | + json.dumps( |
| 19 | + { |
| 20 | + "_pytest": "pytest", |
| 21 | + "_pytest.__init__": "pytest", |
| 22 | + "_pytest._argcomplete": "pytest", |
| 23 | + "_pytest.config.argparsing": "pytest", |
| 24 | + } |
| 25 | + ) |
| 26 | + ) |
| 27 | + |
| 28 | + path2.write_text(json.dumps({"django_types": "django_types"})) |
| 29 | + |
| 30 | + merge_modules_mappings([path1, path2], output_path) |
| 31 | + |
| 32 | + self.assertEqual( |
| 33 | + { |
| 34 | + "_pytest": "pytest", |
| 35 | + "_pytest.__init__": "pytest", |
| 36 | + "_pytest._argcomplete": "pytest", |
| 37 | + "_pytest.config.argparsing": "pytest", |
| 38 | + "django_types": "django_types", |
| 39 | + }, |
| 40 | + json.loads(output_path.read_text()), |
| 41 | + ) |
45 | 42 |
|
46 | 43 |
|
47 | 44 | if __name__ == "__main__": |
|
0 commit comments