Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(603)

Unified Diff: src/caterpillar_test.py

Issue 1675133002: inject_script_tags no longer crashes when there is no body tag. (Closed) Base URL: https://github.com/chromium/caterpillar.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/caterpillar.py ('K') | « src/caterpillar.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/caterpillar_test.py
diff --git a/src/caterpillar_test.py b/src/caterpillar_test.py
index 3d7c83ce675332105d590025962c7d9d548b6919..5d6a999fa1a785d4f39cb90b624e718ec8dc4a6e 100755
--- a/src/caterpillar_test.py
+++ b/src/caterpillar_test.py
@@ -344,13 +344,57 @@ class TestInjectScriptTags(unittest.TestCase):
"""Tests the correct tags are injected if there are many requirements."""
requirements = ['réq', 'uir', 'edf', 'ile', 's.j', 'ava', 'scr', 'ipt']
caterpillar.inject_script_tags(
- self.soup, requirements, 'path', BOILERPLATE_DIR, '')
+ self.soup, requirements, 'path', BOILERPLATE_DIR, '')
for requirement in requirements:
self.assertIsNotNone(
self.soup.find('script',
src=os.path.join('path', BOILERPLATE_DIR,
requirement)))
+ def test_no_body_yes_html(self):
+ """Tests the correct tags are injected if there is no body tag."""
+ html = """\
+<!DOCTYPE html>
+<html>
+<h1>
+ Hello, Wo®ld!
+</h1>
+</html>"""
+ soup = bs4.BeautifulSoup(html, 'html.parser')
+ requirements = ['réq', 'uir']
+ caterpillar.inject_script_tags(
+ soup, requirements, 'path', BOILERPLATE_DIR, '')
+ self.assertEqual(re.sub(r'\s+', ' ', unicode(soup)),
+ re.sub(r'\s+', ' ', """\
+<!DOCTYPE html>
+<html>
+<h1>
+ Hello, Wo®ld!
+</h1>
+<script src="path/bóilerplate dir/réq"></script><script
+ src="path/bóilerplate dir/uir"></script></html>"""))
+
+ def test_no_body_or_html(self):
+ """Tests the correct tags are injected if there is no body or html tag."""
+ html = """\
+<!DOCTYPE html>
+<h1>
+ Hello, Wo®ld!
+</h1>
+"""
+ soup = bs4.BeautifulSoup(html, 'html.parser')
+ requirements = ['réq', 'uir']
+ caterpillar.inject_script_tags(
+ soup, requirements, 'path', BOILERPLATE_DIR, '')
+ self.assertEqual(re.sub(r'\s+', ' ', unicode(soup)),
+ re.sub(r'\s+', ' ', """\
+<!DOCTYPE html>
+<h1>
+ Hello, Wo®ld!
+</h1>
+<script src="path/bóilerplate dir/réq"></script><script
+ src="path/bóilerplate dir/uir"></script>"""))
+
def test_many_requirements_tag_order(self):
"""Tests tags are injected in order."""
requirements = ['réq', 'uir', 'edf', 'ile', 's.j', 'ava', 'scr', 'ipt']
« src/caterpillar.py ('K') | « src/caterpillar.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698