Example #1
0
    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))
Example #2
0
    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, ))
Example #3
0
    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, ))
Example #4
0
    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, ))
Example #5
0
    def test_set_recent_file_dict(self):
        css_directory = settings.css_directory                                              # Save original setting
        settings.css_directory = unittest_file_path(folder='test_recent')                   # Change Setting

        make_directory(settings.css_directory)                                              # Create dir for Travis CI
        self.assertTrue(os.path.isdir(settings.css_directory))

        css_file = unittest_file_path(settings.css_directory, 'blowdry.css')
        with open(css_file, 'w') as generic_file:
            generic_file.write('.bold {font-weight: bold}')

        temp_file = unittest_file_path('test_recent', 'new.html')                           # Create a temporary file
        with open(temp_file, 'w') as generic_file:
            generic_file.write('<html></html>')

        valid_dict = {
            '.html': {
                unittest_file_path('test_recent', 'new.html'),
            },
            '.aspx': set(),
            '.jinja2': set(),
        }
        valid_keys = ['.html', '.aspx', '.jinja2']
        settings.file_types = ('*.html', '*.aspx', '*.jinja2')                              # Override file_types
        project_directory = settings.project_directory
        settings.project_directory = unittest_file_path()
        file_finder = FileFinder(recent=True)
        for valid_key in valid_keys:
            self.assertTrue(valid_key in file_finder.file_dict, msg=file_finder.file_dict)
            self.assertEqual(
                file_finder.file_dict[valid_key],
                valid_dict[valid_key],
                msg='\n' + valid_key + str(file_finder.file_dict[valid_key]) + '\n\n' + str(valid_dict[valid_key])
            )

        delete_file_paths(file_paths=(temp_file, css_file, ))                               # Delete test files
        settings.css_directory = css_directory                                              # Reset settings
        settings.file_types = ('*.html', )
        settings.project_directory = project_directory
Example #6
0
    def test_build_file_path_list(self):
        delete_these = (
            unittest_file_path("test_examplesite", "clashing_aliases.html"),
            unittest_file_path("test_examplesite", "modify.html"),
            unittest_file_path("test_examplesite", "property_aliases.html"),
        )
        delete_file_paths(file_paths=delete_these)

        expected_file_paths = {
            # unittest_file_path('test_examplesite', 'clashing_aliases.html'),
            # unittest_file_path('test_examplesite', 'modify.html'),
            # unittest_file_path('test_examplesite', 'property_aliases.html'),
            unittest_file_path("test_generic", "blowdry.html"),
            unittest_file_path("test_html", "index.html"),
            unittest_file_path("test_html", "media_query.html"),
            unittest_file_path("test_html", "test.html"),
            unittest_file_path("test_aspx", "test.aspx"),
            unittest_file_path("test_jinja", "test.jinja2"),
        }
        settings.file_types = ("*.html", "*.aspx", "*.jinja2")  # Override file_types
        project_directory = settings.project_directory
        settings.project_directory = unittest_file_path()
        file_finder = FileFinder(recent=False)
        self.assertTrue(".aspx" in list(file_finder.file_dict), msg=settings.file_types)
        class_parser = ClassParser(file_dict=file_finder.file_dict)
        self.assertEqual(
            set(class_parser.file_path_list),
            expected_file_paths,
            msg="\n"
            + str(set(class_parser.file_path_list))
            + "\n"
            + str(expected_file_paths)
            + "\nsettings: "
            + str(settings.html_docs),
        )
        settings.file_types = ("*.html",)  # Reset file_types
        settings.project_directory = project_directory
Example #7
0
    def test_set_file_dict(self):
        delete_these = (
            unittest_file_path('test_examplesite', 'clashing_aliases.html'),
            unittest_file_path('test_examplesite', 'modify.html'),
            unittest_file_path('test_examplesite', 'property_aliases.html'),
        )
        delete_file_paths(file_paths=delete_these)

        valid_dict = {
            '.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'),
            },
            '.aspx': {
                unittest_file_path('test_aspx', 'test.aspx'),
            },
            '.jinja2': {
                unittest_file_path('test_jinja', 'test.jinja2'),
            }
        }
        valid_keys = ['.html', '.aspx', '.jinja2']
        settings.file_types = ('*.html', '*.aspx', '*.jinja2')                              # Override file_types
        project_directory = settings.project_directory
        settings.project_directory = unittest_file_path()
        file_finder = FileFinder(recent=False)
        for valid_key in valid_keys:
            self.assertTrue(valid_key in file_finder.file_dict, msg=file_finder.file_dict)
            self.assertEqual(
                file_finder.file_dict[valid_key],
                valid_dict[valid_key],
                msg='\n' + valid_key + str(file_finder.file_dict[valid_key]) + '\n\n' + str(valid_dict[valid_key])
            )
        settings.file_types = ('*.html', )                                                  # Reset file_types
        settings.project_directory = project_directory
    def test_main_auto_generate_False_css_text_Fully_Integrated_Test(self):
        # Integration test that checks blowdry.css and blowdry.min.css output.
        logging.basicConfig(level=logging.DEBUG)
        expected_css_text = """.h444-hover:hover {
    color: #444
    }
.height-200 {
    height: 12.5em
    }
.talign-center {
    text-align: center
    }
.bgc-h000 {
    background-color: #000
    }
.fantasy {
    font-family: fantasy
    }
.padding-5 {
    padding: 0.3125em
    }
.c-blue {
    color: blue
    }
.display-none {
    display: none
    }
.t-align-center {
    text-align: center
    }
.padding-top-10 {
    padding-top: 0.625em
    }
.rgb-255-255-255 {
    color: rgb(255, 255, 255)
    }
.margin-top-30 {
    margin-top: 1.875em
    }
.bold {
    font-weight: bold
    }
.border-1px-solid-gray {
    border: 1px solid gray
    }
.sans-serif {
    font-family: sans-serif
    }
.height-150px {
    height: 9.375em
    }
.margin-top-10 {
    margin-top: 0.625em
    }
.border-5px-solid-hd0d {
    border: 5px solid #d0d
    }
.color-hfff {
    color: #fff
    }
.hfff-hover-i:hover {
    color: #fff !important
    }
.margin-top-50px {
    margin-top: 3.125em
    }
.display-inline {
    display: inline
    }
.red-i-hover:hover {
    color: red !important
    }
.margin-20 {
    margin: 1.25em
    }
.orange {
    color: orange
    }
.margin-25 {
    margin: 1.5625em
    }
.bgc-hf8f8f8 {
    background-color: #f8f8f8
    }
.h484848 {
    color: #484848
    }
.padding-10 {
    padding: 0.625em
    }
.width-50 {
    width: 3.125em
    }
.text-align-center {
    text-align: center
    }
.bgc-h5f2424-i-hover:hover {
    background-color: #5f2424 !important
    }
.width-150 {
    width: 9.375em
    }
.height-50px {
    height: 3.125em
    }
.padding-100-s {
    padding: 6.25em
    }
@media only screen and (max-width: 64em) {
    .padding-100-s {
        padding: 5.9923em
        }
    }
@media only screen and (max-width: 45em) {
    .padding-100-s {
        padding: 5.5556em
        }
    }
@media only screen and (max-width: 30em) {
    .padding-100-s {
        padding: 5em
        }
    }
@media only screen and (max-width: 45.0625em) {
    .large-up {
        display: none
        }
    }
@media only screen and (max-width: 45em) {
    .display-720-up {
        display: none
        }
    }
.font-size-48-s {
    font-size: 3em
    }
@media only screen and (max-width: 64em) {
    .font-size-48-s {
        font-size: 2.8763em
        }
    }
@media only screen and (max-width: 45em) {
    .font-size-48-s {
        font-size: 2.6667em
        }
    }
@media only screen and (max-width: 30em) {
    .font-size-48-s {
        font-size: 2.4em
        }
    }
@media only screen and (max-width: 30.0625em) {
    .display-medium-up {
        display: none
        }
    }
@media only screen and (min-width: 45.0625em) and (max-width: 64em) {
    .padding-100-large-only {
        padding: 6.25em
        }
    }
.font-size-48-s-i {
    font-size: 3em !important
    }
@media only screen and (max-width: 64em) {
    .font-size-48-s-i {
        font-size: 2.8763em !important
        }
    }
@media only screen and (max-width: 45em) {
    .font-size-48-s-i {
        font-size: 2.6667em !important
        }
    }
@media only screen and (max-width: 30em) {
    .font-size-48-s-i {
        font-size: 2.4em !important
        }
    }"""
        expected_css_min_text = ".h444-hover:hover{color:#444}.height-200{height:12.5em}" \
            ".talign-center{text-align:center}" \
            ".bgc-h000{background-color:#000}.fantasy{font-family:fantasy}.padding-5{padding:.3125em}" \
            ".c-blue{color:blue}.display-none{display:none}.t-align-center{text-align:center}" \
            ".padding-top-10{padding-top:.625em}.rgb-255-255-255{color:rgb(255,255,255)}" \
            ".margin-top-30{margin-top:1.875em}.bold{font-weight:bold}" \
            ".border-1px-solid-gray{border:1px solid gray}.sans-serif{font-family:sans-serif}" \
            ".height-150px{height:9.375em}.margin-top-10{margin-top:.625em}" \
            ".border-5px-solid-hd0d{border:5px solid #d0d}.color-hfff{color:#fff}" \
            ".hfff-hover-i:hover{color:#fff !important}.margin-top-50px{margin-top:3.125em}" \
            ".display-inline{display:inline}.red-i-hover:hover{color:red !important}" \
            ".margin-20{margin:1.25em}" \
            ".orange{color:orange}.margin-25{margin:1.5625em}.bgc-hf8f8f8{background-color:#f8f8f8}" \
            ".h484848{color:#484848}.padding-10{padding:.625em}.width-50{width:3.125em}" \
            ".text-align-center{text-align:center}" \
            ".bgc-h5f2424-i-hover:hover{background-color:#5f2424 !important}.width-150{width:9.375em}" \
            ".height-50px{height:3.125em}.padding-100-s{padding:6.25em}" \
            "@media only screen and (max-width:64em){.padding-100-s{padding:5.9923em}}" \
            "@media only screen and (max-width:45em){.padding-100-s{padding:5.5556em}}" \
            "@media only screen and (max-width:30em){.padding-100-s{padding:5em}}" \
            "@media only screen and (max-width:45.0625em){.large-up{display:none}}" \
            "@media only screen and (max-width:45em){.display-720-up{display:none}}" \
            ".font-size-48-s{font-size:3em}@media only screen and (max-width:64em){" \
            ".font-size-48-s{font-size:2.8763em}}@media only screen and (max-width:45em){" \
            ".font-size-48-s{font-size:2.6667em}}@media only screen and (max-width:30em){" \
            ".font-size-48-s{font-size:2.4em}}@media only screen and (max-width:30.0625em){" \
            ".display-medium-up{display:none}}@media only screen and (min-width:45.0625em) and " \
            "(max-width:64em){.padding-100-large-only{padding:6.25em}}.font-size-48-s-i{" \
            "font-size:3em !important}@media only screen and (max-width:64em){.font-size-48-s-i{" \
            "font-size:2.8763em !important}}@media only screen and (max-width:45em){.font-size-48-s-i{" \
            "font-size:2.6667em !important}}@media only screen and (max-width:30em){.font-size-48-s-i{" \
            "font-size:2.4em !important}}"
        html_text = """<html>
            <head>
                <meta charset="UTF-8">
                <meta name="viewport" content="width=device-width, initial-scale=1.0">
                <title>blowdrycss - example site</title>
                <link rel="icon" type="image/x-icon" href="images/favicon.ico">
                <link rel="stylesheet" type="text/css" href="css/blowdry.min.css" />
            </head>

            <body>
                <!-- Title -->
                <h1 class="c-blue hfff-hover-i bgc-h5f2424-i-hover text-align-center display-medium-up font-size-48-s">
                    Blow Dry CSS
                </h1>
                <div>
                    <img src="images/why-blow-dry.jpg" alt="Blow Dry CSS" title="Blow Dry CSS" width=480 />
                </div>

                <div class="t-align-center margin-top-50px large-up">
                    <img class="width-150 height-150px" src="images/blow.jpg" alt="blow" title="blow" />
                    <img class=" width-50 height-50px" src="images/plus.png" alt="plus" title="plus" />
                    <img class="width-150 height-150px" src="images/dry-ground.jpg" alt="dry" title="dry" />
                    <img class=" width-50 height-50px" src="images/plus.png" alt="plus" title="plus" />
                    <img class="width-150 height-150px" src="images/css.jpg" alt="css" title="css" />
                </div>

                <!-- Blow Dryers -->
                <ul class="margin-top-10">
                    <li class="bold padding-top-10">
                        <div>
                            <img class="height-200" src="images/blow-dryer1.jpg" alt="hair-yer1" title="blow-dryer1" />
                        </div>
                        <div class="color-hfff bgc-h000 padding-100-large-only">
                            A blow dryer drys the dryer of the hair.
                            <br class="display-none" />
                            This should be on the same line i.e. br-tag should be hidden once css is applied.
                        </div>
                    </li>

                    <li class="font-size-48-s-i padding-top-10">
                        <div>
                            <img class="height-200" src="images/blow-dryer2.jpg" alt="hadryer2" title="blow-dryer2" />
                        </div>
                        <div class="h484848 bgc-h000">
                            A blow dryer drys the hair of the dryer of hair.
                        </div>
                    </li>

                    <li class="b padding-top-10">
                        <div>
                            <img class="height-200" src="images/blow-dryer3.jpg" alt="ha-dryer3" title="blow-dryer3" />
                        </div>
                        <div class="color-#fff bgc-#000">
                            A blow dryer drys the dryer of hair. Intentional WRONG HEX ENCODING
                        </div>
                    </li>

                    <li class="b padding-top-10 h444-hover">
                        <div class="">
                            <img class="height-200 border-5px-solid-hd0d" src="images/blow-dryer4.jpg" />
                        </div>
                        <div class="rgb-255-255-255 bgc-h000">
                            <h3 class="sans-serif">
                                A blow dryer <span class="fantasy orange">drys</span> the dryer of hair.
                            </h3>
                        </div>
                    </li>
                </ul>

                <div class="hfff h000000-hover">Testing</div>

                <!-- <p class="margin-left-123">Class should not be found in comments</p> -->
                <h1 class="c-blue  text-align-center padding-10 display-720-up">Blow Dry CSS</h1>
                <div id="div1">Should have margin of 25px all the way around. Javascript class selectors.</div>
                <div class="padding-100-s margin-20 red-i-hover margin-top-30 border-5px-solid-hd0d">
                    Testing<br class="hide" />1 2 3
                </div>

                <script>
                    // create element
                    var element = document.getElementById("div1");
                    // element.classList.add() variant 1
                    element.classList.add("margin-25");
                </script>
            </body>
        </html>"""
        test_examplesite = unittest_file_path(folder='test_examplesite')
        test_css = unittest_file_path(folder='test_examplesite/test_css')
        blowdry_css = unittest_file_path(folder=test_css, filename='blowdry.css')
        blowdry_min_css = unittest_file_path(folder=test_css, filename='blowdry.min.css')
        test_dot_html = unittest_file_path(folder='test_examplesite', filename='test.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(test_dot_html, 'w') as _file:
            _file.write(html_text)

        self.assertTrue(path.isfile(test_dot_html))

        settings.auto_generate = False
        watchdogwrapper.main()
        sleep(0.25)

        # Human-readable CSS
        with open(blowdry_css, 'r') as css_text:
            self.assertTrue(expected_css_text, css_text.read())

        # Minified CSS
        with open(blowdry_min_css, 'r') as css_min_text:
            self.assertTrue(expected_css_min_text, css_min_text.read())

        delete_file_paths((test_dot_html, blowdry_css, blowdry_min_css, ))                          # Delete test html
        settings.auto_generate = auto_generate                                                      # reset setting