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

Side by Side Diff: platform_tools/android/tests/generate_user_config_tests.py

Issue 242203008: Allow running gyp_to_android without SkUserConfig. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: copyfileobj, tests, gyp_to_android executable. Created 6 years, 8 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 unified diff | Download patch
« no previous file with comments | « platform_tools/android/tests/expectations/missing-filename.xxx ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 # Copyright 2014 Google Inc. 3 # Copyright 2014 Google Inc.
4 # 4 #
5 # Use of this source code is governed by a BSD-style license that can be 5 # Use of this source code is governed by a BSD-style license that can be
6 # found in the LICENSE file. 6 # found in the LICENSE file.
7 7
8 """ 8 """
9 Test generate_user_config.py. 9 Test generate_user_config.py.
10 """ 10 """
11 11
12 import argparse 12 import argparse
13 import os 13 import os
14 import shutil 14 import shutil
15 import sys 15 import sys
16 import tempfile 16 import tempfile
17 import test_variables 17 import test_variables
18 import unittest 18 import unittest
19 import utils 19 import utils
20 20
21 sys.path.append(test_variables.GYP_GEN_DIR) 21 sys.path.append(test_variables.GYP_GEN_DIR)
22 22
23 from generate_user_config import generate_user_config as gen_config 23 from generate_user_config import generate_user_config as gen_config
24 24
25 # Name of SkUserConfig file. 25 # Name of SkUserConfig file.
26 USER_CONFIG_NAME = 'SkUserConfig-h.txt' 26 USER_CONFIG_NAME = 'SkUserConfig-h.txt'
27 MISSING_FILENAME = 'missing-filename.xxx'
27 # Path to unchanging Dummy SkUserConfig file. 28 # Path to unchanging Dummy SkUserConfig file.
28 FULL_DUMMY_PATH = os.path.join(os.path.dirname(__file__), 'inputs', 29 FULL_DUMMY_PATH = os.path.join(os.path.dirname(__file__), 'inputs',
29 USER_CONFIG_NAME) 30 USER_CONFIG_NAME)
30 REBASELINE_MSG = ('If you\'ve modified generate_user_config.py, run ' 31 REBASELINE_MSG = ('If you\'ve modified generate_user_config.py, run '
31 '"generate_user_config_tests.py --rebaseline" to rebaseline') 32 '"generate_user_config_tests.py --rebaseline" to rebaseline')
32 33
33 def generate_dummy_user_config(original_sk_user_config, target_dir): 34 def generate_dummy_user_config(original_sk_user_config,
35 require_sk_user_config, target_dir):
34 # Add an arbitrary set of defines 36 # Add an arbitrary set of defines
35 defines = [ 'SK_BUILD_FOR_ANDROID', 37 defines = [ 'SK_BUILD_FOR_ANDROID',
36 'SK_BUILD_FOR_ANDROID_FRAMEWORK', 38 'SK_BUILD_FOR_ANDROID_FRAMEWORK',
37 'SK_SCALAR_IS_FLOAT', 39 'SK_SCALAR_IS_FLOAT',
38 'foo', 40 'foo',
39 'bar' ] 41 'bar' ]
40 gen_config(original_sk_user_config=original_sk_user_config, 42 gen_config(original_sk_user_config=original_sk_user_config,
43 require_sk_user_config=require_sk_user_config,
41 target_dir=target_dir, ordered_set=defines) 44 target_dir=target_dir, ordered_set=defines)
42 45
43 46
44 class GenUserConfigTest(unittest.TestCase): 47 class GenUserConfigTest(unittest.TestCase):
45 48
46 def test_missing_sk_user_config(self): 49 def test_missing_sk_user_config(self):
47 tmp = tempfile.mkdtemp() 50 tmp = tempfile.mkdtemp()
48 original = os.path.join(tmp, 'filename') 51 original = os.path.join(tmp, MISSING_FILENAME)
49 assert not os.path.exists(original) 52 assert not os.path.exists(original)
50 53
54
55 # With require_sk_user_config set to True, an AssertionError will be
56 # thrown when original_sk_user_config is missing.
51 with self.assertRaises(AssertionError): 57 with self.assertRaises(AssertionError):
52 ordered_set = [ 'define' ] 58 ordered_set = [ 'define' ]
53 gen_config(original_sk_user_config=original, target_dir=tmp, 59 gen_config(original_sk_user_config=original,
54 ordered_set=ordered_set) 60 require_sk_user_config=True,
61 target_dir=tmp, ordered_set=ordered_set)
62
63 # With require_sk_user_config set to False, it is okay for
64 # original_sk_user_config to be missing.
65 generate_dummy_user_config(original_sk_user_config=original,
66 require_sk_user_config=False, target_dir=tmp)
67 actual_name = os.path.join(tmp, MISSING_FILENAME)
68 utils.compare_to_expectation(actual_name=actual_name,
69 expectation_name=MISSING_FILENAME,
70 assert_true=self.assertTrue,
71 msg=REBASELINE_MSG)
72
55 shutil.rmtree(tmp) 73 shutil.rmtree(tmp)
56 74
57 def test_gen_config(self): 75 def test_gen_config(self):
58 tmp = tempfile.mkdtemp() 76 tmp = tempfile.mkdtemp()
59 generate_dummy_user_config(FULL_DUMMY_PATH, tmp) 77 generate_dummy_user_config(FULL_DUMMY_PATH, True, tmp)
60 actual_name = os.path.join(tmp, USER_CONFIG_NAME) 78 actual_name = os.path.join(tmp, USER_CONFIG_NAME)
61 utils.compare_to_expectation(actual_name=actual_name, 79 utils.compare_to_expectation(actual_name=actual_name,
62 expectation_name=USER_CONFIG_NAME, 80 expectation_name=USER_CONFIG_NAME,
63 assert_true=self.assertTrue, msg=REBASELINE_MSG) 81 assert_true=self.assertTrue, msg=REBASELINE_MSG)
64 shutil.rmtree(tmp) 82 shutil.rmtree(tmp)
65 83
66 84
67 def main(): 85 def main():
68 loader = unittest.TestLoader() 86 loader = unittest.TestLoader()
69 suite = loader.loadTestsFromTestCase(GenUserConfigTest) 87 suite = loader.loadTestsFromTestCase(GenUserConfigTest)
70 results = unittest.TextTestRunner(verbosity=2).run(suite) 88 results = unittest.TextTestRunner(verbosity=2).run(suite)
71 print repr(results) 89 print repr(results)
72 if not results.wasSuccessful(): 90 if not results.wasSuccessful():
73 raise Exception('failed one or more unittests') 91 raise Exception('failed one or more unittests')
74 92
75 93
76 def rebaseline(): 94 def rebaseline():
77 generate_dummy_user_config(FULL_DUMMY_PATH, utils.EXPECTATIONS_DIR) 95 generate_dummy_user_config(FULL_DUMMY_PATH, True, utils.EXPECTATIONS_DIR)
96 generate_dummy_user_config(MISSING_FILENAME, False, utils.EXPECTATIONS_DIR)
78 97
79 if __name__ == "__main__": 98 if __name__ == "__main__":
80 parser = argparse.ArgumentParser() 99 parser = argparse.ArgumentParser()
81 parser.add_argument('-r', '--rebaseline', help='Rebaseline expectations.', 100 parser.add_argument('-r', '--rebaseline', help='Rebaseline expectations.',
82 action='store_true') 101 action='store_true')
83 args = parser.parse_args() 102 args = parser.parse_args()
84 103
85 if args.rebaseline: 104 if args.rebaseline:
86 rebaseline() 105 rebaseline()
87 else: 106 else:
88 main() 107 main()
89 108
OLDNEW
« no previous file with comments | « platform_tools/android/tests/expectations/missing-filename.xxx ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698