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

Unified Diff: infra/tools/new_tool/test/new_tool_test.py

Issue 1172053003: Created infra/tools/new_tool (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: More tests Created 5 years, 6 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
« no previous file with comments | « infra/tools/new_tool/test/data/test_template.template ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: infra/tools/new_tool/test/new_tool_test.py
diff --git a/infra/tools/new_tool/test/new_tool_test.py b/infra/tools/new_tool/test/new_tool_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..bec5f9eb901fc37be72139a9f003e70e42538eda
--- /dev/null
+++ b/infra/tools/new_tool/test/new_tool_test.py
@@ -0,0 +1,83 @@
+# Copyright 2015 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 argparse
+import os
+import unittest
+
+from infra.tools.new_tool import new_tool
+import infra_libs
+
+
+DATA_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data')
+
+
+class TestArgParseOptions(unittest.TestCase):
+ def test_add_argparse_options_smoke(self):
+ parser = argparse.ArgumentParser()
+ new_tool.add_argparse_options(parser)
+
+
+class TestGenerateToolFiles(unittest.TestCase):
+ def test_generate(self):
+ with infra_libs.temporary_directory(prefix='new-tool-test-') as tempdir:
+ toolname = 'test_tool'
+ new_tool.generate_tool_files('test_tool', tempdir)
+ self.assertTrue(os.path.isdir(os.path.join(tempdir, toolname)))
+ self.assertTrue(os.path.isfile(os.path.join(tempdir, toolname,
+ '__init__.py')))
+ self.assertTrue(os.path.isfile(os.path.join(tempdir, toolname,
+ '__main__.py')))
+ self.assertTrue(os.path.isdir(os.path.join(tempdir, toolname, 'test')))
+ self.assertTrue(os.path.isfile(os.path.join(tempdir, toolname, 'test',
+ '__init__.py')))
+
+ def test_no_overwrite_tool(self):
+ with infra_libs.temporary_directory(prefix='new-tool-test-') as tempdir:
+ self.assertFalse(new_tool.generate_tool_files('test_tool', tempdir))
+ self.assertTrue(new_tool.generate_tool_files('test_tool', tempdir))
+
+ def test_missing_destination_dir(self):
+ with infra_libs.temporary_directory(prefix='new-tool-test-') as tempdir:
+ # When destination directory does not exist, just do nothing and return
+ # a non-zero value.
+ self.assertTrue(new_tool.generate_tool_files(
+ 'test_tool', os.path.join(tempdir, 'missing-directory')))
+
+
+class TestGeneratePythonFile(unittest.TestCase):
+ def test_generate_empty_file(self):
+ with infra_libs.temporary_directory(prefix='new-tool-test-') as tempdir:
+ filename = new_tool.generate_python_file(tempdir, 'test.py', None)
+ self.assertTrue(os.path.isfile(filename))
+ # Read the content and do some basic check
+ with open(filename, 'r') as f:
+ content = f.read()
+ self.assertTrue(content.startswith(new_tool.COPYRIGHT_NOTICE))
+
+ # Now make sure the file is not overwritten
+ new_content = 'other content'
+ with open(filename, 'w') as f:
+ f.write(new_content)
+ filename2 = new_tool.generate_python_file(tempdir, 'test.py', None)
+ self.assertEqual(filename, filename2)
+ with open(filename, 'r') as f:
+ content = f.read()
+ self.assertEqual(content, new_content)
+
+ def test_generate_file_from_template(self):
+ with infra_libs.temporary_directory(prefix='new-tool-test-') as tempdir:
+ filename = new_tool.generate_python_file(
+ tempdir, 'test.py', 'test_template', template_dir=DATA_DIR,
+ value='Passed string.')
+ self.assertTrue(os.path.isfile(filename))
+
+ # Read the content
+ with open(filename, 'r') as f:
+ content = f.read()
+
+ expected_content = (new_tool.COPYRIGHT_NOTICE
+ + 'This is a template used by the test suite.\n'
+ 'Passed string.\n')
+ self.assertEqual(content, expected_content)
« no previous file with comments | « infra/tools/new_tool/test/data/test_template.template ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698