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

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

Issue 140503007: Scripts to generate Android.mk for framework Skia. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Respond to Elliot's comments in patch set 20. Created 6 years, 10 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
(Empty)
1 #!/usr/bin/python
2
3 # Copyright 2014 Google Inc.
4 #
5 # Use of this source code is governed by a BSD-style license that can be
6 # found in the LICENSE file.
7
8 """
9 Test gyp_to_android.py
10 """
11
12 import os
13 import shutil
14 import sys
15 import tempfile
16 import test_variables
17 import unittest
18
19 # Path to gyp_to_android
20 sys.path.append(test_variables.BIN_DIR)
21
22 import gyp_to_android
23
24 class AndroidMkCreationTest(unittest.TestCase):
25
26 def setUp(self):
27 # Create a temporary directory for storing the output (Android.mk)
28 self.__tmp_dir = tempfile.mkdtemp()
29
30 def test_create(self):
31 gyp_to_android.main(self.__tmp_dir)
32
33 # 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')
35 self.assertTrue(os.path.exists(path_to_android_mk))
36
37 def tearDown(self):
38 # Remove self.__tmp_dir, which is no longer needed.
39 shutil.rmtree(self.__tmp_dir)
40
41
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():
99 loader = unittest.TestLoader()
100 suite = loader.loadTestsFromTestCase(AndroidMkCreationTest)
101 suite.addTest(loader.loadTestsFromTestCase(CleanGypdTest))
102 unittest.TextTestRunner(verbosity=2).run(suite)
103
104 if __name__ == "__main__":
105 main()
OLDNEW
« no previous file with comments | « platform_tools/android/gyp_gen/vars_dict_lib.py ('k') | platform_tools/android/tests/ordered_set_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698