예제 #1
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)
예제 #2
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
예제 #3
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
예제 #4
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
예제 #5
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
예제 #6
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
예제 #7
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
예제 #8
0
 def test_cleaner_invalid_minified(self):
     # The minified option must be true or false
     with pytest.raises(ArgumentParserError):
         CSSCleaner(options={'css-cleaner-min': 'nonsense'})