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

Unified Diff: tools/grit/grit/flatten_resource_runner_unittest.py

Issue 2094193004: Strip comments and whitespace from Javascript resources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to comments, plus rebases. Created 4 years, 5 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
Index: tools/grit/grit/flatten_resource_runner_unittest.py
diff --git a/tools/grit/grit/flatten_resource_runner_unittest.py b/tools/grit/grit/flatten_resource_runner_unittest.py
new file mode 100755
index 0000000000000000000000000000000000000000..360464797a16974989606d295ee02c416bd9c416
--- /dev/null
+++ b/tools/grit/grit/flatten_resource_runner_unittest.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import os
+import sys
+if __name__ == '__main__':
Dan Beam 2016/07/14 17:47:58 why do you need to do this only if __name__ == '__
+ sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
Dan Beam 2016/07/14 17:47:58 can you just do this in the other if __name__ == '
+
+import unittest
+import tempfile
Dan Beam 2016/07/14 17:47:58 nit: alpha
+
+from grit import flatten_resource_runner
+
+
+class FlattenResourceRunnerUnitest(unittest.TestCase):
+
+ def testIf(self):
+ '''Tests that a -D option is correctly handled'''
+ with tempfile.NamedTemporaryFile() as input_file,\
+ tempfile.NamedTemporaryFile() as output_file:
Dan Beam 2016/07/14 17:47:58 where do these get deleted?
+ input_file.write('Hello <if expr="T1==1"> good</if>'
+ '<if expr="T2==2"> bad</if> test')
+ input_file.seek(0)
Dan Beam 2016/07/14 17:47:58 what's this seek(0) for? can we just close() inst
+ flatten_resource_runner.Main(['-DT1=1',
+ input_file.name,
+ output_file.name])
+ self.failUnlessEqual('Hello good test', output_file.read())
+ pass
+
+ def testInclude(self):
+ '''Tests that an include is correctly handled'''
+ with tempfile.NamedTemporaryFile() as input_file,\
+ tempfile.NamedTemporaryFile() as output_file,\
+ tempfile.NamedTemporaryFile() as include_file:
+ input_file.write('<include src="' + include_file.name + '">')
+ input_file.seek(0)
+ include_file.write('Hello included')
+ include_file.seek(0)
+ flatten_resource_runner.Main([input_file.name, output_file.name])
+ self.failUnlessEqual('Hello included', output_file.read())
+ pass
+
+
+if __name__ == '__main__':
+ unittest.main()

Powered by Google App Engine
This is Rietveld 408576698