Chromium Code Reviews| 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() |