66import unittest
77
88from 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 ]}
1014
1115
1216class Tests (unittest .TestCase ):
@@ -20,3 +24,23 @@ def test_deps(self):
2024 os .rmdir (temp_dir )
2125 ensure_dependencies (DEV_DEPENDENCIES , pathlib .Path (temp_dir ), silent = True )
2226 self .assertGreater (len (os .listdir (temp_dir )), 0 )
27+
28+ @unittest .skipUnless (os .environ .get ('TEST_DEPENDENCIES' ), 'skipping dependency test' )
29+ def test_cleanup_deps (self ):
30+ to_clean = {k : v [1 ] for k , v in TESTED_DEPENDENCIES .items ()}
31+ with tempfile .TemporaryDirectory () as temp_dir :
32+ ensure_dependencies (TESTED_DEPENDENCIES , pathlib .Path (temp_dir ), silent = True )
33+ self .assertGreater (len (os .listdir (temp_dir )), 0 )
34+ cleanup_old_dependencies (to_clean , pathlib .Path (temp_dir ))
35+ self .assertEqual (len (os .listdir (temp_dir )), 0 )
36+ cleanup_old_dependencies (to_clean , pathlib .Path (temp_dir ))
37+ with tempfile .TemporaryDirectory () as temp_dir :
38+ ensure_dependencies (TESTED_DEPENDENCIES , pathlib .Path (temp_dir ), silent = True )
39+ count = len (os .listdir (temp_dir ))
40+ self .assertGreater (count , 0 )
41+ with tempfile .TemporaryDirectory () as temp_backup_dir :
42+ os .rmdir (temp_backup_dir )
43+ cleanup_old_dependencies (to_clean , pathlib .Path (temp_dir ),
44+ pathlib .Path (temp_backup_dir ))
45+ self .assertEqual (len (os .listdir (temp_backup_dir )), count )
46+ self .assertEqual (len (os .listdir (temp_dir )), 0 )
0 commit comments