def test_delete_file_paths(self): file_paths = ( unittest_file_path('test_examplesite', 'file1.html'), unittest_file_path('test_examplesite', 'file2.html'), unittest_file_path('test_examplesite', 'file3.html'), ) # create files to delete text = 'test123' make_directory(unittest_file_path('test_examplesite', '')) for file_path in file_paths: with open(file_path, 'wb') as generic_file: generic_file.write(bytearray(text, 'utf-8')) # assert they exist for file_path in file_paths: self.assertTrue(path.isfile(file_path)) # delete them delete_file_paths(file_paths=file_paths) # assert they don't exist for file_path in file_paths: self.assertFalse(path.isfile(file_path))
def test_main_auto_generate_True_on_modify(self): # Integration test logging.basicConfig(level=logging.DEBUG) html_text = '<html></html>' test_examplesite = unittest_file_path(folder='test_examplesite') test_css = unittest_file_path(folder='test_examplesite/test_css') delete_dot_html = unittest_file_path(folder='test_examplesite', filename='delete.html') # Directory must be created for Travis CI case make_directory(test_examplesite) make_directory(test_css) self.assertTrue(path.isdir(test_examplesite)) self.assertTrue(path.isdir(test_css)) # Create file delete.html with open(delete_dot_html, 'w') as _file: _file.write(html_text) # Double check to ensure it got created. self.assertTrue(path.isfile(delete_dot_html)) auto_generate = settings.auto_generate # original settings.auto_generate = True _thread.start_new_thread(self.monitor_modify_delete_stop, (delete_dot_html,)) sleep(0.25) # Required for Travis CI watchdogwrapper.main() # Caution: Nothing will run after this line unless _thread.interrupt_main() is called. self.assertTrue(self.passing, msg=self.non_matching + ' not found in output:\n' + self.output) settings.auto_generate = auto_generate # reset setting
def test_main_auto_generate_True_limit_timer_expired(self): # Integration test logging.basicConfig(level=logging.DEBUG) html_text = '<html><div class="blue"></div></html>' test_examplesite = unittest_file_path(folder='test_examplesite') test_css = unittest_file_path(folder='test_examplesite/test_css') limit_dot_html = unittest_file_path(folder='test_examplesite', filename='limit_expired.html') # Directory must be created for Travis CI case make_directory(test_examplesite) make_directory(test_css) self.assertTrue(path.isdir(test_examplesite)) self.assertTrue(path.isdir(test_css)) # Create file limit_expired.html with open(limit_dot_html, 'w') as _file: _file.write(html_text) # Double check to ensure it got created. self.assertTrue(path.isfile(limit_dot_html)) auto_generate = settings.auto_generate # original time_limit = settings.time_limit settings.auto_generate = True settings.time_limit = 0.1 # reduce the time_limit _thread.start_new_thread(self.monitor_limit_expires_stop, ()) watchdogwrapper.main() # Caution: Nothing will run after this line unless _thread.interrupt_main() is called. self.assertTrue(self.passing, msg=self.non_matching + ' not found in output:\n' + self.output) remove(limit_dot_html) # delete files settings.auto_generate = auto_generate # reset setting settings.time_limit = time_limit
def test_boilerplate_rst_docs(self): # Save original values. project_directory = settings.project_directory docs_directory = settings.docs_directory rst_docs = settings.rst_docs # Change settings settings.project_directory = unittest_file_path(folder='test_examplesite') # Prevent 'examplesite' creation. settings.docs_directory = unittest_file_path(folder='test_docs') settings.rst_docs = True expected_files = ( os.path.join(settings.docs_directory, 'clashing_aliases.rst'), os.path.join(settings.docs_directory, 'property_aliases.rst'), ) for expected_file in expected_files: # Ensure the files do not exist. if os.path.isfile(expected_file): os.remove(expected_file) blowdry.boilerplate() for expected_file in expected_files: self.assertTrue(os.path.isfile(expected_file), msg=expected_file) os.remove(expected_file) # Delete # Reset settings values. settings.project_directory = project_directory settings.docs_directory = docs_directory settings.rst_docs = rst_docs
def test_unittest_file_path_exact_path(self): folder = 'test_html' filename = 'index.html' cwd = getcwd() expected_if_path = path.join(cwd, folder, filename) expecetd_else_path = path.join(cwd, 'blowdrycss', 'unit_tests', folder, filename) test_path = unittest_file_path(folder=folder, filename=filename) if cwd.endswith('unit_tests'): # Allows running of pycharm unittest. self.assertTrue(test_path, expected_if_path) chdir('../..') test_path = unittest_file_path(folder=folder, filename=filename) # Re-run for else path. cwd_else = getcwd() expecetd_else_path = path.join(cwd_else, 'blowdrycss', 'unit_tests', folder, filename) self.assertTrue(test_path, expecetd_else_path) else: # Run unittest cmd from the root directory. self.assertTrue(test_path, expecetd_else_path) chdir(path.join(cwd, 'blowdrycss', 'unit_tests')) test_path = unittest_file_path(folder=folder, filename=filename) # Re-run for else path. cwd_if = getcwd() expected_if_path = path.join(cwd_if, folder, filename) self.assertTrue(test_path, expected_if_path) chdir(cwd) # Return current directory.
def test_parse_on_modify_css_text_PREXISTING(self): # WARNING Indentation must be preserved. expected_css_text = b""".green { color: green } .pink-hover:hover { color: pink }""" substrings = [ '~~~ blowdrycss started ~~~', 'CSSBuilder Running...', '.css', ] project_directory = settings.project_directory css_directory = settings.css_directory settings.project_directory = unittest_file_path() settings.css_directory = unittest_file_path() current_set = {'green', } current_css_text = b""".green { color: green } """ css_file = unittest_file_path(filename='blowdry.css') # CSS file css_min_file = unittest_file_path(filename='blowdry.min.css') # CSS.min file with open(css_file, 'w') as generic_file: generic_file.write('test test test') modify_file = unittest_file_path(filename='modify.html') # Modify file with open(modify_file, 'w') as generic_file: generic_file.write('<html><div class="pink-hover not-valid">Modified</div></html>') saved_stdout = sys.stdout try: out = StringIO() sys.stdout = out class_set, css_text = blowdry.parse(recent=True, class_set=current_set, css_text=current_css_text) self.assertTrue(expected_css_text == css_text, msg=css_text) output = out.getvalue() for substring in substrings: self.assertTrue(substring in output, msg=output + '\tsubstring: ' + substring) finally: sys.stdout = saved_stdout settings.project_directory = project_directory settings.css_directory = css_directory delete_file_paths((css_file, css_min_file, modify_file, ))
def test_excluded_True(self): excluded_true = [ unittest_file_path(folder=str('test_examplesite'), filename=str('clashing_aliases.html')), unittest_file_path(folder=str('test_examplesite'), filename=str('property_aliases.html')), ] file_types = '(' + ', '.join(settings.file_types) + ')' event_handler = FileEditEventHandler( patterns=list(file_types), ignore_patterns=[], ignore_directories=True ) for excluded in excluded_true: self.assertTrue(event_handler.excluded(src_path=excluded))
def test_excluded_False(self): excluded_false = [ unittest_file_path(folder='test_examplesite', filename='index.html'), unittest_file_path(folder='test_examplesite', filename='test.html'), ] file_types = '(' + ', '.join(settings.file_types) + ')' event_handler = FileEditEventHandler( patterns=list(file_types), ignore_patterns=[], ignore_directories=True ) for excluded in excluded_false: self.assertFalse(event_handler.excluded(src_path=excluded))
def test_build_class_set_php_file(self): # integration test expected_class_set = { "blue", "padding-bottom-80", "margin-top-75-i", "hff9900", "<?php", "echo", "$order_status;", "?>", "entry-content", "row", "margin-top-0", "white", # Short Code classes embedded in PHP. } settings.file_types = ("*.php",) # Override file_types project_directory = settings.project_directory settings.project_directory = unittest_file_path() file_finder = FileFinder(recent=False) self.assertFalse(".html" in list(file_finder.file_dict), msg=settings.file_types) self.assertTrue(".php" in list(file_finder.file_dict), msg=settings.file_types) class_parser = ClassParser(file_dict=file_finder.file_dict) self.assertEqual(class_parser.class_set, expected_class_set, msg=class_parser.class_set) settings.file_types = ("*.html",) # Reset file_types settings.project_directory = project_directory
def test_make_directory_pre_existing(self): directory_name = 'test_html' # pre-existing case directory = unittest_file_path(folder=directory_name) self.assertTrue(path.isdir(directory)) make_directory(directory=directory) # should do nothing self.assertTrue(path.isdir(directory))
def test_is_valid_extension_false(self): wrong_extensions = ['.wrong', '.squirrel', '.incorrect'] file_path = unittest_file_path('test_aspx', 'test.aspx') for wrong_extension in wrong_extensions: file_regex_map = FileRegexMap(file_path=file_path) file_regex_map.extension = wrong_extension self.assertFalse(file_regex_map.is_valid_extension())
def test_get_file_as_string(self): test_file_path = unittest_file_path('test_html', 'test.html') expected_string = ( '<html> <body> ' + '<!-- <p class="margin-left-22"> Class should not be found in comments' + ' </p> --> ' + '<h1 class="c-blue text-align-center padding-10 display-960-up-i">Blow Dry CSS</h1> ' + '<div id="div1" class="padding-10-s margin-20 c-red-i-hover">Testing<br class="hide" />1 2 3</div>' + ' <p class="hfff-hover-i">Stars</p> ' + '</body></html><script> // create element var element = document.getElementById("div1"); ' + 'var notimplemented = " not implemented "; // element.classList.add() variant 1 ' + 'element.classList.add("addclass1"); // element.classList.add() variant 2 ' + 'element.classList.add( "addclass2" ); // element.classList.add() variant 3 ' + 'element.classList.add( "addclass3" ); // element.classList.add() variant 4 ' + 'element.classList.add(\'addclass4\'); // element.classList.add() variant 5 ' + 'element.classList.add( \'addclass5\' ); // element.classList.add() variant 6 ' + 'element.classList.add( \'addclass6\' ); // className variables not implemented ' + 'element.classList.add(notimplemented);</script>' ) file_converter = FileConverter(file_path=test_file_path) self.assertEqual( file_converter.get_file_as_string(), expected_string, msg='\n' + file_converter.get_file_as_string() + '\n' + expected_string )
def test_unittest_file_path(self): folders = ['test_aspx', 'test_jinja', ] filenames = ['test.aspx', 'test.jinja2', ] for i, folder in enumerate(folders): the_path = unittest_file_path(folder, filenames[i]) self.assertTrue(path.isfile(the_path))
def test_raw_class_list_aspx(self): expected_raw_class_list = [ ' row bgc-green padding-top-30 padding-bottom-30', 'bgc-pink', 'color-h979591', 'row padding-top-30 padding-bottom-30 ', 'row padding-top-30 padding-bottom-30 ', 'row padding-25-820-up ', 'row', 'font-size-12 arial h4b4f54 margin-top-33', 'font-size-42 bold h333333 margin-top-13', # These two were missed in the past. (URI / Inline comment match issue) 'small-6 medium-4 large-3 xlarge-2 xxlarge-2 columns end padding-left-5-i padding-right-5-i margin-top-10', 'bgc-h1989ce width-250 hide', 'small-12 columns text-align-center margin-top-40', 'inline-block bgc-h333333 width-140 height-48 white bold padding-top-16 padding-bottom-19 border-radius-5', # These two were missed in the past. (URI / Inline comment match issue) 'inline-block bgc-h1989ce width-250 height-48 white bold padding-top-16 padding-bottom-19 border-radius-5 margin-left-16', 'material-icons vertical-align-middle font-size-18-i', # Embedded <script></script> 'jquery1', 'jquery2', 'jquery3', 'jquery4 jquery5', 'jquery6 jquery7', 'jquery8', 'jquery9 jquery10', 'jquery11', 'jquery12 jquery13', 'jquery14', 'jquery15', 'jquery16', 'jquery17', ] aspx_file = unittest_file_path('test_aspx', 'test.aspx') class_extractor = ClassExtractor(file_path=aspx_file) actual_raw_class_list = class_extractor.raw_class_list self.assertEqual(actual_raw_class_list, expected_raw_class_list, msg=actual_raw_class_list)
def test_parse(self): expected_class_set = { u'medium-up', u'border-1px-solid-gray', u'padding-5', u'margin-top-10', u'display-none', u'width-50', u'height-150px', u'color-hfff', u'font-size-25-s', u't-align-center', u'display-inline', u'margin-top-50px', u'talign-center', u'width-150', u'display-960-up-i', u'font-size-48', u'bold', u'margin-20', u'bgc-h000', u'c-red-i-hover', u'hfff-hover-i', u'padding-10', u'bgc-hf8f8f8', u'text-align-center', u'c-blue', u'height-200', u'padding-10-s', u'height-50px', u'padding-top-10', # Invalid though they exist in the HTML # u'addclass3', u'addclass6', u'addclass1', u'addclass4', u'addclass5', u'hide', u'alex-grey-125', u'b', } substrings = [ '~~~ blowdrycss started ~~~', 'CSSBuilder Running...', '.css', ] project_directory = settings.project_directory settings.project_directory = unittest_file_path() saved_stdout = sys.stdout try: out = StringIO() sys.stdout = out class_set, css_text = blowdry.parse(recent=False, class_set=set(), css_text=b'') self.assertTrue(expected_class_set == class_set, msg=class_set) output = out.getvalue() for substring in substrings: self.assertTrue(substring in output, msg=output + '\tsubstring: ' + substring) finally: sys.stdout = saved_stdout settings.project_directory = project_directory
def test_set_files(self): expected_files = { # unittest_file_path('test_examplesite', 'clashing_aliases.html'), # unittest_file_path('test_examplesite', 'property_aliases.html'), # unittest_file_path('test_examplesite', 'modify.html'), unittest_file_path('test_generic', 'blowdry.html'), unittest_file_path('test_html', 'index.html'), unittest_file_path('test_html', 'test.html'), unittest_file_path('test_html', 'media_query.html'), } project_directory = settings.project_directory settings.project_directory = unittest_file_path() file_finder = FileFinder(recent=False) for expected_file in expected_files: self.assertTrue(expected_file in file_finder.files) settings.project_directory = project_directory # Reset
def test_main_auto_generate_False_print_statements(self): # Integration test logging.basicConfig(level=logging.DEBUG) substrings = [ '~~~ blowdrycss started ~~~', 'Auto-Generated CSS', 'Completed', 'blowdry.css', 'blowdry.min.css', ] html_text = '<html></html>' test_examplesite = unittest_file_path(folder='test_examplesite') test_css = unittest_file_path(folder='test_css') delete_dot_html = unittest_file_path(folder='test_examplesite', filename='delete.html') auto_generate = settings.auto_generate # original # Directory must be created for Travis CI case make_directory(test_examplesite) make_directory(test_css) self.assertTrue(path.isdir(test_examplesite)) self.assertTrue(path.isdir(test_css)) # Create delete.html with open(delete_dot_html, 'w') as _file: _file.write(html_text) self.assertTrue(path.isfile(delete_dot_html)) saved_stdout = sys.stdout try: out = StringIO() sys.stdout = out settings.auto_generate = False watchdogwrapper.main() sleep(0.25) # IMPORTANT: Must wait for output otherwise test will fail. output = out.getvalue() for substring in substrings: self.assertTrue(substring in output, msg=substring + '\noutput:\n' + output) finally: sys.stdout = saved_stdout remove(delete_dot_html) # Delete delete.html settings.auto_generate = auto_generate # reset setting
def test_parse_on_modify_class_set(self): expected_class_set = { 'green', 'purple-medium-up', 'bgc-h454545', # Pre-existing 'pink-hover', # Modify.html # Exists in HTML but should not be returned # 'not-valid', } substrings = [ '~~~ blowdrycss started ~~~', 'CSSBuilder Running...', '.css', ] project_directory = settings.project_directory css_directory = settings.css_directory settings.project_directory = unittest_file_path() settings.css_directory = unittest_file_path() current_set = {'green', 'purple-medium-up', 'bgc-h454545', } css_file = unittest_file_path(filename='blowdry.css') # CSS file css_min_file = unittest_file_path(filename='blowdry.min.css') # CSS.min file with open(css_file, 'w') as generic_file: generic_file.write('test test test') modify_file = unittest_file_path(filename='modify.html') # Modify file with open(modify_file, 'w') as generic_file: generic_file.write('<html><div class="pink-hover not-valid">Modified</div></html>') saved_stdout = sys.stdout try: out = StringIO() sys.stdout = out class_set, css_text = blowdry.parse(recent=True, class_set=current_set) self.assertTrue(expected_class_set == class_set, msg=class_set) output = out.getvalue() for substring in substrings: self.assertTrue(substring in output, msg=output + '\tsubstring: ' + substring) finally: sys.stdout = saved_stdout settings.project_directory = project_directory settings.css_directory = css_directory delete_file_paths((css_file, css_min_file, modify_file, ))
def test_regexes(self): sub_uri = (r'://', ) sub_js = ( r'//.*?\n', # Remove JS Comments. r'\n', # Remove new lines before block quotes. r'/\*.*?\*/', # Remove block quotes. r'(domClass.add\(\s*.*?,\s*["\'])', # dojo r'(domClass.add\(\s*.*?,\s*["\'])', r'(dojo.addClass\(\s*.*?,\s*["\'])', r'(domClass.remove\(\s*.*?,\s*["\'])', r'(dojo.removeClass\(\s*.*?,\s*["\'])', r'(YAHOO.util.Dom.addClass\(\s*.*?,\s*["\'])', # yui r'(YAHOO.util.Dom.hasClass\(\s*.*?,\s*["\'])', r'(YAHOO.util.Dom.removeClass\(\s*.*?,\s*["\'])', r'(.addClass\(\s*["\'])', # jquery r'(.removeClass\(\s*["\'])', r'(\$\(\s*["\']\.)', ) sub_html = sub_uri + sub_js + (r'<!--.*?-->', ) sub_dotnet = sub_html + (r'<%--.*?--%>', r'<%.*?%>', ) js_substring = r'extract__class__set' findall_regex_js = ( r'.classList.add\(\s*[\'"](.*?)["\']\s*\)', r'.classList.remove\(\s*[\'"](.*?)["\']\s*\)', r'.className\s*\+?=\s*.*?[\'"](.*?)["\']', r'.getElementsByClassName\(\s*[\'"](.*?)["\']\s*\)', r'.setAttribute\(\s*[\'"]class["\']\s*,\s*[\'"](.*?)["\']\s*\)', js_substring + r'\(\s*[\'"](.*?)["\']\s*\)', # Find cases designated by js_substring. ) expected_dicts = [ { 'sub_regexes': sub_dotnet, 'findall_regexes': (r'class=[\'"](.*?)["\']', ) + findall_regex_js, }, { 'sub_regexes': (r'{.*?}?}', ) + sub_html + (r'{#.*?#}', ), 'findall_regexes': (r'class=[\'"](.*?)["\']', ) + findall_regex_js, }, ] file_paths = [unittest_file_path('test_aspx', 'test.aspx'), unittest_file_path('test_jinja', 'test.jinja2')] for i, _path in enumerate(file_paths): file_regex_map = FileRegexMap(file_path=_path) actual_dict = file_regex_map.regex_dict self.assertEqual(actual_dict, expected_dicts[i], msg=_path)
def test_invalid_initialization(self): generic_directory = unittest_file_path('test_generic') file_name = 'blowdry' extension = '.md' self.assertRaises(ValueError, GenericFile, '', file_name, extension) self.assertRaises(ValueError, GenericFile, generic_directory, '', extension) self.assertRaises(ValueError, GenericFile, generic_directory, file_name, '')
def test_write_invalid_input(self): invalid_inputs = [1239487.234, ['nth', 'rcghtn'], {2, 1, '&^'}, 546, ] generic_directory = unittest_file_path('test_generic') file_name = 'blowdry' extension = '.md' for invalid_text in invalid_inputs: generic_file = GenericFile(file_directory=generic_directory, file_name=file_name, extension=extension) self.assertRaises(TypeError, generic_file.write, invalid_text)
def test_integration_class_set_ruby_erb(self): expected_class_set = { 'font-size-53', 'brown', 'text-align-right', 'medium-down', # Embedded <script></script> 'yui1', 'yui2', 'yui3', 'yui4', 'yui5', 'yui6', 'yui7', 'yui8', } erb_file = unittest_file_path('test_erb', 'test.erb') class_extractor = ClassExtractor(file_path=erb_file) actual_class_set = class_extractor.class_set self.assertEqual(actual_class_set, expected_class_set)
def test_minify_created(self): css_directory = unittest_file_path(folder='test_css') file_name = 'blowdry' css_file = CSSFile(file_directory=css_directory, file_name=file_name) file_path = path.join(css_directory, css_file.file_name + '.min.css') if path.isfile(file_path): # Ensure that file is deleted before testing. remove(file_path) css_file.minify() self.assertTrue(path.isfile(file_path))
def test_raw_class_list_jinja(self): expected_raw_class_list = [ 'purple padding-left-5', ' squirrel text-align-center margin-5-2-5-2-1000-up', 'large-up border-1', 'row text-align-center', '', # Embedded <script></script> 'dojo1', 'dojo2', 'dojo3 dojo4', 'dojo5 dojo6', 'dojo7', 'dojo8', 'dojo9 dojo10', 'dojo11 dojo12', ] jinja2_file = unittest_file_path('test_jinja', 'test.jinja2') class_extractor = ClassExtractor(file_path=jinja2_file) actual_raw_class_list = class_extractor.raw_class_list self.assertEqual(actual_raw_class_list, expected_raw_class_list)
def test_integration_class_set_html(self): expected_class_set = { 'c-blue', 'text-align-center', 'padding-10', 'margin-20', 'hide', 'display-960-up-i', 'padding-10-s', 'c-red-i-hover', 'hfff-hover-i', # Embedded <script></script> 'addclass1', 'addclass2', 'addclass3', 'addclass4', 'addclass5', 'addclass6', } html_file = unittest_file_path('test_html', 'test.html') class_extractor = ClassExtractor(file_path=html_file) actual_class_set = class_extractor.class_set self.assertEqual(actual_class_set, expected_class_set)
def test_print_css_stats(self): # On Travis CI these auto-generated files are inaccessible and need to be recreated. # Change the expected file size reduction percentage since Ubuntu's math is different. # Create directories and CSS files if they do not exist. blowdry_css = unittest_file_path('test_examplesite/test_css', 'blowdry.css') blowdry_min_css = unittest_file_path('test_examplesite/test_css', 'blowdry.min.css') #if not path.isfile(blowdry_css) or not path.isfile(blowdry_min_css): substrings = [ 'blowdry.css:\t 0.3kB', 'blowdry.min.css: 0.2kB', 'CSS file size reduced by 28.4%.' ] blowdry_css_text = '.bgc-hf8f8f8 {\n background-color: #f8f8f8\n }\n.border-1px-solid-gray {\n border: 1px solid gray\n }\n.padding-5 {\n padding: 0.3125em\n }\n.bold {\n font-weight: bold\n }\n.talign-center {\n text-align: center\n }\n.display-inline {\n display: inline\n }' blowdry_min_css_text = '.bgc-hf8f8f8{background-color:#f8f8f8}.border-1px-solid-gray{border:1px solid gray}.padding-5{padding:.3125em}.bold{font-weight:bold}.talign-center{text-align:center}.display-inline{display:inline}' # Create directories. make_directory(unittest_file_path('test_examplesite', '')) make_directory(unittest_file_path('test_examplesite/test_css', '')) # Create files. with open(blowdry_css, 'wb') as generic_file: generic_file.write(bytearray(blowdry_css_text, 'utf-8')) with open(blowdry_min_css, 'wb') as generic_file: generic_file.write(bytearray(blowdry_min_css_text, 'utf-8')) # Handle printed output. saved_stdout = sys.stdout try: out = StringIO() sys.stdout = out print_css_stats(file_name='blowdry') output = out.getvalue() for substring in substrings: self.assertTrue(substring in output, msg=substring + '\noutput:\n' + output) finally: sys.stdout = saved_stdout
def test_integration_class_set_jinja(self): expected_class_set = { 'purple', 'padding-left-5', 'squirrel', 'text-align-center', 'large-up', 'border-1', 'row', 'text-align-center', 'margin-5-2-5-2-1000-up', # Embedded <script></script> 'dojo1', 'dojo2', 'dojo3', 'dojo4', 'dojo5', 'dojo6', 'dojo7', 'dojo8', 'dojo9', 'dojo10', 'dojo11', 'dojo12', } jinja2_file = unittest_file_path('test_jinja', 'test.jinja2') class_extractor = ClassExtractor(file_path=jinja2_file) actual_class_set = class_extractor.class_set self.assertEqual(actual_class_set, expected_class_set)
def test_print_css_stats_ZeroDivisionError(self): # On Travis CI these auto-generated files are inaccessible and need to be recreated. # Change the expected file size reduction percentage since Ubuntu's math is different. # Create directories and CSS files if they do not exist. empty_css = unittest_file_path('test_examplesite/test_css', 'empty.css') empty_min_css = unittest_file_path('test_examplesite/test_css', 'empty.min.css') #if not path.isfile(blowdry_css) or not path.isfile(blowdry_min_css): substrings = [ 'empty.css:\t 0.0kB', 'empty.min.css: 0.0kB', 'CSS file size reduced by 0.0%.' ] # Create directories. make_directory(unittest_file_path('test_examplesite', '')) make_directory(unittest_file_path('test_examplesite/test_css', '')) # Create files. with open(empty_css, 'w') as generic_file: generic_file.write(u'') with open(empty_min_css, 'w') as generic_file: generic_file.write(u'') # Handle printed output. saved_stdout = sys.stdout try: out = StringIO() sys.stdout = out print_css_stats(file_name='empty') output = out.getvalue() for substring in substrings: self.assertTrue(substring in output, msg=substring + '\noutput:\n' + output) finally: sys.stdout = saved_stdout delete_file_paths((empty_css, empty_min_css, ))
def test_build_class_set_vue_file(self): # integration test expected_class_set = {"blue", "testing-123", "text-align-center", "incremental", "cssclasses"} settings.file_types = ("*.vue",) # Override file_types project_directory = settings.project_directory settings.project_directory = unittest_file_path() file_finder = FileFinder(recent=False) self.assertFalse(".html" in list(file_finder.file_dict), msg=settings.file_types) self.assertTrue(".vue" in list(file_finder.file_dict), msg=settings.file_types) class_parser = ClassParser(file_dict=file_finder.file_dict) self.assertEqual(class_parser.class_set, expected_class_set, msg=class_parser.class_set) settings.file_types = ("*.html",) # Reset file_types settings.project_directory = project_directory
def test_make_directory_non_existing(self): directory_name = 'test_make_directory' directory = unittest_file_path(folder=directory_name) if path.isdir(directory): # Remove test directory removedirs(directory) self.assertFalse(path.isdir(directory)) make_directory(directory=directory) self.assertTrue(path.isdir(directory)) if path.isdir(directory): # Remove test directory removedirs(directory)