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

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

Issue 235883015: Generate tests/Android.mk from gyp (Closed) Base URL: https://skia.googlesource.com/skia.git@generate
Patch Set: Remove Android.mk/SkUserConfig.h Created 6 years, 7 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
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 gyp_to_android.py 9 Test gyp_to_android.py
10 """ 10 """
11 11
12 import os 12 import os
13 import shutil 13 import shutil
14 import sys 14 import sys
15 import tempfile 15 import tempfile
16 import test_variables 16 import test_variables
17 import unittest 17 import unittest
18 18
19 # Path to gyp_to_android 19 # Path to gyp_to_android
20 sys.path.append(test_variables.BIN_DIR) 20 sys.path.append(test_variables.BIN_DIR)
21 21
22 import gyp_to_android 22 import gyp_to_android
23 23
24
25
24 class AndroidMkCreationTest(unittest.TestCase): 26 class AndroidMkCreationTest(unittest.TestCase):
25 27
26 def setUp(self): 28 def setUp(self):
27 # Create a temporary directory for storing the output (Android.mk) 29 # Create a temporary directory for storing the output (Android.mk)
28 self.__tmp_dir = tempfile.mkdtemp() 30 self.__tmp_dir = tempfile.mkdtemp()
29 31
30 def test_create(self): 32 def test_create(self):
31 gyp_to_android.main(self.__tmp_dir) 33 gyp_to_android.main(self.__tmp_dir)
32 34
33 # Now there should be a file named 'Android.mk' inside __tmp_dir 35 # Now there should be a file named 'Android.mk' inside __tmp_dir
34 path_to_android_mk = os.path.join(self.__tmp_dir, 'Android.mk') 36 path_to_android_mk = os.path.join(self.__tmp_dir,
37 test_variables.ANDROID_MK)
35 self.assertTrue(os.path.exists(path_to_android_mk)) 38 self.assertTrue(os.path.exists(path_to_android_mk))
36 39
40 # In addition, there should be an 'Android.mk' inside /tests/
41 path_to_tests_android_mk = os.path.join(self.__tmp_dir, 'tests',
42 test_variables.ANDROID_MK)
43 self.assertTrue(os.path.exists(path_to_tests_android_mk))
44
37 def tearDown(self): 45 def tearDown(self):
38 # Remove self.__tmp_dir, which is no longer needed. 46 # Remove self.__tmp_dir, which is no longer needed.
39 shutil.rmtree(self.__tmp_dir) 47 shutil.rmtree(self.__tmp_dir)
40 48
41 49
42 GYPD_SUFFIX = ".gypd"
43 GYP_SUFFIX = ".gyp"
44 GYPI_SUFFIX = ".gypi"
45 OTHER_SUFFIX = ".txt"
46
47 class CleanGypdTest(unittest.TestCase):
48
49 def setUp(self):
50 self.__tmp_dir = tempfile.mkdtemp()
51 self.__num_files = 10
52 # Fill the dir with four types of files. .gypd files should be deleted by
53 # clean_gypd_files(), while the rest should be left alone.
54 for i in range(self.__num_files):
55 self.create_file('%s%s' % (str(i), GYPD_SUFFIX))
56 self.create_file('%s%s' % (str(i), GYPI_SUFFIX))
57 self.create_file('%s%s' % (str(i), GYP_SUFFIX))
58 self.create_file('%s%s' % (str(i), OTHER_SUFFIX))
59
60 def create_file(self, basename):
61 """
62 Create a file named 'basename' in self.__tmp_dir.
63 """
64 f = tempfile.mkstemp(dir=self.__tmp_dir)
65 os.rename(f[1], os.path.join(self.__tmp_dir, basename))
66 self.assert_file_exists(basename)
67
68 def assert_file_exists(self, basename):
69 """
70 Assert that 'basename' exists in self.__tmp_dir.
71 """
72 full_name = os.path.join(self.__tmp_dir, basename)
73 self.assertTrue(os.path.exists(full_name))
74
75 def assert_file_does_not_exist(self, basename):
76 """
77 Assert that 'basename' does not exist in self.__tmp_dir.
78 """
79 full_name = os.path.join(self.__tmp_dir, basename)
80 self.assertFalse(os.path.exists(full_name))
81
82 def test_clean(self):
83 """
84 Test that clean_gypd_files() deletes .gypd files, and leaves others.
85 """
86 gyp_to_android.clean_gypd_files(self.__tmp_dir)
87 for i in range(self.__num_files):
88 self.assert_file_exists('%s%s' % (str(i), GYPI_SUFFIX))
89 self.assert_file_exists('%s%s' % (str(i), GYP_SUFFIX))
90 self.assert_file_exists('%s%s' % (str(i), OTHER_SUFFIX))
91 # Only the GYPD files should have been deleted.
92 self.assert_file_does_not_exist('%s%s' % (str(i), GYPD_SUFFIX))
93
94 def tearDown(self):
95 shutil.rmtree(self.__tmp_dir)
96
97
98 def main(): 50 def main():
99 loader = unittest.TestLoader() 51 loader = unittest.TestLoader()
100 suite = loader.loadTestsFromTestCase(AndroidMkCreationTest) 52 suite = loader.loadTestsFromTestCase(AndroidMkCreationTest)
101 suite.addTest(loader.loadTestsFromTestCase(CleanGypdTest))
102 unittest.TextTestRunner(verbosity=2).run(suite) 53 unittest.TextTestRunner(verbosity=2).run(suite)
103 54
104 if __name__ == "__main__": 55 if __name__ == "__main__":
105 main() 56 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698