Coverage for src/test/test_utils.py: 100%

21 statements  

« prev     ^ index     » next       coverage.py v7.3.0, created at 2024-10-10 12:25 +0000

1import unittest 

2import tempfile 

3import pathlib 

4 

5from .. import utils 

6 

7 

8class TestUtils(unittest.TestCase): 

9 def test_pave_webroot(self): 

10 with tempfile.TemporaryDirectory() as t: 

11 webroot = pathlib.Path(t) 

12 

13 # Delete nothing on an empty directory 

14 count = utils.pave_webroot(webroot) 

15 self.assertEqual(count, 0) 

16 

17 # Delete HTML files 

18 for i in range(4): 

19 (webroot / f'{i}.html').touch() 

20 count = utils.pave_webroot(webroot) 

21 self.assertEqual(count, 4) 

22 

23 # Ignore subfolders 

24 subfolder = (webroot / 'subfolder') 

25 subfolder.mkdir() 

26 save_me = subfolder / 'test.html' 

27 save_me.touch() 

28 count = utils.pave_webroot(webroot) 

29 self.assertEqual(count, 0) 

30 self.assertTrue(save_me.is_file())