|
6 | 6 | import unittest |
7 | 7 |
|
8 | 8 | from open_fortran_parser.config import DEV_DEPENDENCIES |
9 | | -from open_fortran_parser.dependencies import ensure_dependencies |
| 9 | +from open_fortran_parser.dependencies import ensure_dependencies, cleanup_old_dependencies |
| 10 | + |
| 11 | +EXAMPLE_DEPENDENCY = 'Apache Commons CLI 1.4' |
| 12 | + |
| 13 | +TESTED_DEPENDENCIES = {EXAMPLE_DEPENDENCY: DEV_DEPENDENCIES[EXAMPLE_DEPENDENCY]} |
10 | 14 |
|
11 | 15 |
|
12 | 16 | class Tests(unittest.TestCase): |
13 | 17 |
|
14 | 18 | @unittest.skipUnless(os.environ.get('TEST_DEPENDENCIES'), 'skipping dependency test') |
15 | 19 | def test_deps(self): |
16 | 20 | with tempfile.TemporaryDirectory() as temp_dir: |
17 | | - ensure_dependencies(DEV_DEPENDENCIES, pathlib.Path(temp_dir), silent=False) |
| 21 | + self.assertEqual(len(os.listdir(temp_dir)), 0) |
| 22 | + ensure_dependencies(TESTED_DEPENDENCIES, pathlib.Path(temp_dir), download=False) |
| 23 | + self.assertEqual(len(os.listdir(temp_dir)), 0) |
| 24 | + ensure_dependencies(TESTED_DEPENDENCIES, pathlib.Path(temp_dir), silent=False) |
18 | 25 | self.assertGreater(len(os.listdir(temp_dir)), 0) |
| 26 | + ensure_dependencies(TESTED_DEPENDENCIES, pathlib.Path(temp_dir), silent=False) |
19 | 27 | with tempfile.TemporaryDirectory() as temp_dir: |
20 | 28 | os.rmdir(temp_dir) |
21 | | - ensure_dependencies(DEV_DEPENDENCIES, pathlib.Path(temp_dir), silent=True) |
| 29 | + ensure_dependencies(TESTED_DEPENDENCIES, pathlib.Path(temp_dir), silent=True) |
22 | 30 | self.assertGreater(len(os.listdir(temp_dir)), 0) |
| 31 | + |
| 32 | + @unittest.skipUnless(os.environ.get('TEST_DEPENDENCIES'), 'skipping dependency test') |
| 33 | + def test_cleanup_deps(self): |
| 34 | + to_clean = {k: v[1] for k, v in TESTED_DEPENDENCIES.items()} |
| 35 | + with tempfile.TemporaryDirectory() as temp_dir: |
| 36 | + ensure_dependencies(TESTED_DEPENDENCIES, pathlib.Path(temp_dir), silent=True) |
| 37 | + self.assertGreater(len(os.listdir(temp_dir)), 0) |
| 38 | + cleanup_old_dependencies(to_clean, pathlib.Path(temp_dir)) |
| 39 | + self.assertEqual(len(os.listdir(temp_dir)), 0) |
| 40 | + cleanup_old_dependencies(to_clean, pathlib.Path(temp_dir)) |
| 41 | + with tempfile.TemporaryDirectory() as temp_dir: |
| 42 | + ensure_dependencies(TESTED_DEPENDENCIES, pathlib.Path(temp_dir), silent=True) |
| 43 | + count = len(os.listdir(temp_dir)) |
| 44 | + self.assertGreater(count, 0) |
| 45 | + with tempfile.TemporaryDirectory() as temp_backup_dir: |
| 46 | + os.rmdir(temp_backup_dir) |
| 47 | + cleanup_old_dependencies(to_clean, pathlib.Path(temp_dir), |
| 48 | + pathlib.Path(temp_backup_dir)) |
| 49 | + self.assertEqual(len(os.listdir(temp_backup_dir)), count) |
| 50 | + self.assertEqual(len(os.listdir(temp_dir)), 0) |
0 commit comments