def test_non_html_ignored(self, workdir):
     # Non .html/.xhtml files are ignored
     proc = CSSCleaner()
     sample_path = workdir / "src" / "sample.txt"
     sample_path.write("Sample file.")
     resultpath, metadata = proc.process(str(sample_path), {'error': False})
     # input was not touched
     assert resultpath == str(sample_path)
Example #2
0
 def test_non_html_ignored(self, workdir):
     # Non .html/.xhtml files are ignored
     proc = CSSCleaner()
     sample_path = workdir / "src" / "sample.txt"
     sample_path.write("Sample file.")
     resultpath, metadata = proc.process(str(sample_path), {'error': False})
     # input was not touched
     assert resultpath == str(sample_path)
Example #3
0
 def test_non_html_ignored(self):
     # Non .html/.xhtml files are ignored
     proc = CSSCleaner()
     sample_path = os.path.join(self.workdir, 'sample.txt')
     open(sample_path, 'w').write('Sample file.')
     self.resultpath, metadata = proc.process(
         sample_path, {'error': False})
     # input was not touched
     assert self.resultpath == sample_path
 def test_cleaner_non_prettify_is_default(self, workdir, samples_dir):
     # we get non-prettified HTML from CSS cleaner by default
     samples_dir.join("sample2.html").copy(workdir / "src" / "sample.html")
     proc = CSSCleaner()
     resultpath, metadata = proc.process(
         str(workdir / "src" / "sample.html"), {'error': False}, )
     with codecs.open(resultpath, 'r', 'utf-8') as fd:
         result_html = fd.read()
     assert u'seam</span><span>less text.</span>' in result_html
 def test_cleaner_prettify(self, workdir, samples_dir):
     # we can get prettified HTML from CSS cleaner
     # This might result in gaps in rendered output.
     samples_dir.join("sample2.html").copy(workdir / "src" / "sample.html")
     proc = CSSCleaner(options={'css-cleaner-prettify': '1'})
     resultpath, metadata = proc.process(
         str(workdir / "src" / "sample.html"), {'error': False})
     with codecs.open(resultpath, 'r', 'utf-8') as fd:
         result_html = fd.read()
     assert 'seam\n   </span>\n   <span>\n    less' in result_html
 def test_cleaner_css_default_minified(self, workdir, samples_dir):
     # make sure we can get non-minified CSS if we wish so.
     samples_dir.join("sample2.html").copy(workdir / "src" / "sample.html")
     proc = CSSCleaner()
     resultpath, metadata = proc.process(
         str(workdir / "src" / "sample.html"), {'error': False})
     resultdir = os.path.dirname(resultpath)
     result_css = codecs.open(
         os.path.join(resultdir, 'sample.css'), 'r', 'utf-8').read()
     assert 'p{margin-bottom:.21cm}' in result_css
 def test_cleaner_css_correct_css(self, workdir, samples_dir):
     # make sure we get a new CSS file and a link to it in HTML
     samples_dir.join("sample2.html").copy(workdir / "src" / "sample.html")
     proc = CSSCleaner()
     resultpath, metadata = proc.process(
         str(workdir / "src" / "sample.html"), {'error': False})
     resultdir = os.path.dirname(resultpath)
     result_css = codecs.open(
         os.path.join(resultdir, 'sample.css'), 'r', 'utf-8').read()
     assert 'font-family: ;' not in result_css
Example #8
0
    def test_cleaner_css_default_minified(self):
        # make sure we can get non-minified CSS if we wish so.
        proc = CSSCleaner()
        self.resultpath, metadata = proc.process(
            self.sample_path, {'error': False})

        resultdir = os.path.dirname(self.resultpath)
        result_css = open(
            os.path.join(resultdir, 'sample.css'), 'rb').read()
        assert 'p{margin-bottom:.21cm}' in result_css
Example #9
0
 def test_cleaner_css_correct_css(self, workdir, samples_dir):
     # make sure we get a new CSS file and a link to it in HTML
     samples_dir.join("sample2.html").copy(workdir / "src" / "sample.html")
     proc = CSSCleaner()
     resultpath, metadata = proc.process(
         str(workdir / "src" / "sample.html"), {'error': False})
     resultdir = os.path.dirname(resultpath)
     result_css = codecs.open(os.path.join(resultdir, 'sample.css'), 'r',
                              'utf-8').read()
     assert 'font-family: ;' not in result_css
Example #10
0
    def test_cleaner_css_correct_css(self):
        # make sure we get a new CSS file and a link to it in HTML
        proc = CSSCleaner()
        self.resultpath, metadata = proc.process(
            self.sample_path, {'error': False})

        resultdir = os.path.dirname(self.resultpath)
        result_css = open(
            os.path.join(resultdir, 'sample.css'), 'rb').read()
        assert 'font-family: ;' not in result_css
Example #11
0
 def test_cleaner_prettify(self, workdir, samples_dir):
     # we can get prettified HTML from CSS cleaner
     # This might result in gaps in rendered output.
     samples_dir.join("sample2.html").copy(workdir / "src" / "sample.html")
     proc = CSSCleaner(options={'css-cleaner-prettify': '1'})
     resultpath, metadata = proc.process(
         str(workdir / "src" / "sample.html"), {'error': False})
     with codecs.open(resultpath, 'r', 'utf-8') as fd:
         result_html = fd.read()
     assert 'seam\n   </span>\n   <span>\n    less' in result_html
Example #12
0
 def test_cleaner_css_default_minified(self, workdir, samples_dir):
     # make sure we can get non-minified CSS if we wish so.
     samples_dir.join("sample2.html").copy(workdir / "src" / "sample.html")
     proc = CSSCleaner()
     resultpath, metadata = proc.process(
         str(workdir / "src" / "sample.html"), {'error': False})
     resultdir = os.path.dirname(resultpath)
     result_css = codecs.open(os.path.join(resultdir, 'sample.css'), 'r',
                              'utf-8').read()
     assert 'p{margin-bottom:.21cm}' in result_css
Example #13
0
    def test_cleaner_css_non_minified(self):
        # make sure we can get non-minified CSS if we wish so.
        proc = CSSCleaner(options={'css-cleaner-min': '0'})
        self.resultpath, metadata = proc.process(
            self.sample_path, {'error': False})

        resultdir = os.path.dirname(self.resultpath)
        result_css = open(
            os.path.join(resultdir, 'sample.css'), 'rb').read()
        assert 'p {\n    margin-bottom: 0.21cm\n    }\n' in result_css
Example #14
0
 def test_cleaner_non_prettify_is_default(self, workdir, samples_dir):
     # we get non-prettified HTML from CSS cleaner by default
     samples_dir.join("sample2.html").copy(workdir / "src" / "sample.html")
     proc = CSSCleaner()
     resultpath, metadata = proc.process(
         str(workdir / "src" / "sample.html"),
         {'error': False},
     )
     with codecs.open(resultpath, 'r', 'utf-8') as fd:
         result_html = fd.read()
     assert u'seam</span><span>less text.</span>' in result_html
 def test_cleaner(self, workdir, samples_dir):
     # make sure we get a new CSS file and a link to it in HTML
     samples_dir.join("sample2.html").copy(workdir / "src" / "sample.html")
     proc = CSSCleaner()
     resultpath, metadata = proc.process(
         str(workdir / "src" / "sample.html"), {'error': False})
     contents = codecs.open(resultpath, 'r', encoding='utf-8').read()
     snippet = u"%s" % (
         '<link href="sample.css" rel="stylesheet" type="text/css"/>')
     assert u'sample.css' in os.listdir(os.path.dirname(resultpath))
     assert snippet in contents
     assert u'With umlaut: ä' in contents
Example #16
0
 def test_spaces_preserved_by_default(self, workdir, samples_dir):
     # we can be sure that any whitespaces are preserved (by default)
     samples_dir.join("sample-font-props.html").copy(workdir / "src" /
                                                     "sample.html")
     proc = CSSCleaner()
     resultpath, metadata = proc.process(
         str(workdir / "src" / "sample.html"), {'error': False})
     result_html = open(resultpath, 'r').read()
     assert " <sub>sub" in result_html  # space before tag
     assert "sub<sub>script" in result_html  # no space before tag
     assert "sub</sub>script" in result_html  # no space after tag
     assert "script</sub> parts" in result_html  # space after tag
 def test_spaces_preserved_by_default(self, workdir, samples_dir):
     # we can be sure that any whitespaces are preserved (by default)
     samples_dir.join(
         "sample-font-props.html").copy(workdir / "src" / "sample.html")
     proc = CSSCleaner()
     resultpath, metadata = proc.process(
         str(workdir / "src" / "sample.html"), {'error': False})
     result_html = open(resultpath, 'r').read()
     assert " <sub>sub" in result_html             # space before tag
     assert "sub<sub>script" in result_html        # no space before tag
     assert "sub</sub>script" in result_html       # no space after tag
     assert "script</sub> parts" in result_html    # space after tag
Example #18
0
 def test_cleaner(self, workdir, samples_dir):
     # make sure we get a new CSS file and a link to it in HTML
     samples_dir.join("sample2.html").copy(workdir / "src" / "sample.html")
     proc = CSSCleaner()
     resultpath, metadata = proc.process(
         str(workdir / "src" / "sample.html"), {'error': False})
     contents = codecs.open(resultpath, 'r', encoding='utf-8').read()
     snippet = u"%s" % (
         '<link href="sample.css" rel="stylesheet" type="text/css"/>')
     assert u'sample.css' in os.listdir(os.path.dirname(resultpath))
     assert snippet in contents
     assert u'With umlaut: ä' in contents
Example #19
0
    def test_cleaner(self):
        # make sure we get a new CSS file and a link to it in HTML
        proc = CSSCleaner()
        self.resultpath, metadata = proc.process(
            self.sample_path, {'error': False})
        contents = open(self.resultpath, 'rb').read()

        resultdir = os.path.dirname(self.resultpath)
        snippet = "%s" % (
            '<link href="sample.css" rel="stylesheet" type="text/css"/>')
        assert 'sample.css' in os.listdir(resultdir)
        assert snippet in contents
        assert 'With umlaut: ä' in contents