| OLD | NEW | 
|---|
| (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 the VarsDict. | 
|  | 10 """ | 
|  | 11 | 
|  | 12 import sys | 
|  | 13 import test_variables | 
|  | 14 import unittest | 
|  | 15 | 
|  | 16 sys.path.append(test_variables.GYP_GEN_DIR) | 
|  | 17 | 
|  | 18 import vars_dict_lib | 
|  | 19 from vars_dict_lib import OrderedSet | 
|  | 20 from vars_dict_lib import VarsDict | 
|  | 21 from vars_dict_lib import VAR_NAMES | 
|  | 22 | 
|  | 23 class VarsDictTest(unittest.TestCase): | 
|  | 24   """ | 
|  | 25   Tests for the VarsDict class. | 
|  | 26   """ | 
|  | 27 | 
|  | 28   # May not be needed. | 
|  | 29   def setUp(self): | 
|  | 30     self.__vars_dict = VarsDict() | 
|  | 31 | 
|  | 32   def assert_consistency(self, v_dict): | 
|  | 33     self.assertIs(v_dict.LOCAL_CFLAGS, v_dict['LOCAL_CFLAGS']) | 
|  | 34     self.assertIs(v_dict.LOCAL_CPPFLAGS, v_dict['LOCAL_CPPFLAGS']) | 
|  | 35     self.assertIs(v_dict.LOCAL_SRC_FILES, v_dict['LOCAL_SRC_FILES']) | 
|  | 36     self.assertIs(v_dict.LOCAL_SHARED_LIBRARIES, | 
|  | 37                   v_dict['LOCAL_SHARED_LIBRARIES']) | 
|  | 38     self.assertIs(v_dict.LOCAL_STATIC_LIBRARIES, | 
|  | 39                   v_dict['LOCAL_STATIC_LIBRARIES']) | 
|  | 40     self.assertIs(v_dict.LOCAL_C_INCLUDES, v_dict['LOCAL_C_INCLUDES']) | 
|  | 41     self.assertIs(v_dict.LOCAL_EXPORT_C_INCLUDE_DIRS, | 
|  | 42                   v_dict['LOCAL_EXPORT_C_INCLUDE_DIRS']) | 
|  | 43     self.assertIs(v_dict.KNOWN_TARGETS, v_dict['KNOWN_TARGETS']) | 
|  | 44 | 
|  | 45   def test_creation(self): | 
|  | 46     v_dict = VarsDict() | 
|  | 47     # VarsDict has one entry for each label in VAR_NAMES | 
|  | 48     self.assertEqual(len(v_dict.keys()), len(VAR_NAMES)) | 
|  | 49     for key in v_dict.keys(): | 
|  | 50       self.assertIn(key, VAR_NAMES) | 
|  | 51       # Each entry is an empty OrderedSet | 
|  | 52       self.assertIsNotNone(v_dict[key]) | 
|  | 53       self.assertIsInstance(v_dict[key], OrderedSet) | 
|  | 54       self.assertEqual(len(v_dict[key]), 0) | 
|  | 55       self.assert_consistency(v_dict) | 
|  | 56 | 
|  | 57   def test_intersection(self): | 
|  | 58     v_dict_list = [] | 
|  | 59     RANGE = 10 | 
|  | 60     for i in range(RANGE): | 
|  | 61       v_dict = VarsDict() | 
|  | 62       # Add something common to each field, as well as a unique entry | 
|  | 63       v_dict.LOCAL_CFLAGS.add('cflag') | 
|  | 64       v_dict.LOCAL_CFLAGS.add(str(i)) | 
|  | 65 | 
|  | 66       v_dict.LOCAL_CPPFLAGS.add('cppflag') | 
|  | 67       v_dict.LOCAL_CPPFLAGS.add(str(i)) | 
|  | 68 | 
|  | 69       v_dict.LOCAL_SRC_FILES.add('src') | 
|  | 70       v_dict.LOCAL_SRC_FILES.add(str(i)) | 
|  | 71 | 
|  | 72       v_dict.LOCAL_SHARED_LIBRARIES.add('shared') | 
|  | 73       v_dict.LOCAL_SHARED_LIBRARIES.add(str(i)) | 
|  | 74 | 
|  | 75       v_dict.LOCAL_STATIC_LIBRARIES.add('static') | 
|  | 76       v_dict.LOCAL_STATIC_LIBRARIES.add(str(i)) | 
|  | 77 | 
|  | 78       v_dict.LOCAL_C_INCLUDES.add('includes') | 
|  | 79       v_dict.LOCAL_C_INCLUDES.add(str(i)) | 
|  | 80 | 
|  | 81       v_dict.LOCAL_EXPORT_C_INCLUDE_DIRS.add('exports') | 
|  | 82       v_dict.LOCAL_EXPORT_C_INCLUDE_DIRS.add(str(i)) | 
|  | 83 | 
|  | 84       v_dict.KNOWN_TARGETS.add('known') | 
|  | 85       v_dict.KNOWN_TARGETS.add(str(i)) | 
|  | 86 | 
|  | 87       self.assert_consistency(v_dict) | 
|  | 88 | 
|  | 89       v_dict_list.append(v_dict) | 
|  | 90 | 
|  | 91     intersection = vars_dict_lib.intersect(v_dict_list) | 
|  | 92 | 
|  | 93     self.assert_consistency(intersection) | 
|  | 94 | 
|  | 95     for key in intersection.keys(): | 
|  | 96       # Each field had one common item | 
|  | 97       self.assertEqual(len(intersection[key]), 1) | 
|  | 98       for item in intersection[key]: | 
|  | 99         for other_v_dict in v_dict_list: | 
|  | 100           self.assertNotIn(item, other_v_dict[key]) | 
|  | 101 | 
|  | 102 | 
|  | 103 def main(): | 
|  | 104   loader = unittest.TestLoader() | 
|  | 105   suite = loader.loadTestsFromTestCase(VarsDictTest) | 
|  | 106   unittest.TextTestRunner(verbosity=2).run(suite) | 
|  | 107 | 
|  | 108 if __name__ == "__main__": | 
|  | 109   main() | 
|  | 110 | 
| OLD | NEW | 
|---|