1#!/usr/bin/env python3 2 3from filecmp import cmp, dircmp 4from offlinify_dackka_docs import check_library, process_input, STYLE_FILENAME 5import os 6from pathlib import Path 7from shutil import rmtree 8import unittest 9 10TEST_PATH = os.path.join(Path(__file__).parent.absolute(), 'testData') 11OUTPUT_PATH = os.path.join(TEST_PATH, 'temp') 12 13class TestOfflinifyDackkaDocs(unittest.TestCase): 14 def setUp(self): 15 os.mkdir(OUTPUT_PATH) 16 17 def tearDown(self): 18 rmtree(OUTPUT_PATH) 19 20 """ 21 Verify that the directories have the same subdirectories and files. 22 """ 23 def check_dirs(self, actual, expected): 24 css_path = os.path.join(actual, STYLE_FILENAME) 25 self.assertTrue(os.path.exists(css_path)) 26 27 dcmp = dircmp(actual, expected, hide=[STYLE_FILENAME, '.DS_Store']) 28 self.check_dircmp(dcmp) 29 30 """ 31 Recursively process the dircmp result to test the directories and files are equal. 32 """ 33 def check_dircmp(self, dcmp): 34 # Make sure there's nothing in one dir and not the other 35 self.assertEqual(dcmp.left_only, []) 36 self.assertEqual(dcmp.right_only, []) 37 38 # dircmp checks that the same files exist, not that there contents are equal--verify that here 39 for file in dcmp.common_files: 40 left_path = os.path.join(dcmp.left, file) 41 right_path = os.path.join(dcmp.right, file) 42 self.assertTrue(cmp(left_path, right_path, shallow=False)) 43 44 for sub, sub_dcmp in dcmp.subdirs.items(): 45 self.check_dircmp(sub_dcmp) 46 47 def test_all_libraries(self): 48 input_path = os.path.join(TEST_PATH, 'input') 49 process_input(input_path, OUTPUT_PATH, None) 50 51 expected_output_path = os.path.join(TEST_PATH, 'outputAllLibs') 52 self.check_dirs(OUTPUT_PATH, expected_output_path) 53 54 def test_one_library(self): 55 input_path = os.path.join(TEST_PATH, 'input') 56 library = check_library('library', input_path, OUTPUT_PATH) 57 process_input(input_path, OUTPUT_PATH, library) 58 59 expected_output_path = os.path.join(TEST_PATH, 'outputOneLib') 60 self.check_dirs(OUTPUT_PATH, expected_output_path) 61 62if __name__ == '__main__': 63 unittest.main() 64