def test_merge_three_conditions(self): values = { ('linux',): { 'isolate_dependency_tracked': ['file_common', 'file_linux'], }, ('mac',): { 'isolate_dependency_tracked': ['file_common', 'file_mac'], }, ('win',): { 'isolate_dependency_tracked': ['file_common', 'file_win'], }, } expected = { 'conditions': [ ['OS=="linux"', { 'variables': { 'isolate_dependency_tracked': [ 'file_linux', ], }, }], ['OS=="linux" or OS=="mac" or OS=="win"', { 'variables': { 'isolate_dependency_tracked': [ 'file_common', ], }, }], ['OS=="mac"', { 'variables': { 'isolate_dependency_tracked': [ 'file_mac', ], }, }], ['OS=="win"', { 'variables': { 'isolate_dependency_tracked': [ 'file_win', ], }, }], ], } actual = isolate.convert_map_to_isolate_dict( isolate.reduce_inputs(isolate.invert_map(values)), ('OS',)) self.assertEqual(expected, actual)
def test_reduce_inputs_take_strongest_dependency(self): values = { 'command': { ('echo', 'Hello World'): set(['atari']), ('echo', 'You should get an Atari'): set(['amiga', 'coleco', 'dendy']), }, KEY_TRACKED: { 'a': set(['amiga', 'atari', 'coleco', 'dendy']), 'b': set(['amiga', 'atari', 'coleco']), }, KEY_UNTRACKED: { 'c': set(['amiga', 'atari', 'coleco', 'dendy']), 'd': set(['amiga', 'coleco', 'dendy']), }, KEY_TOUCHED: { 'a': set(['amiga', 'atari', 'coleco', 'dendy']), 'b': set(['atari', 'coleco', 'dendy']), 'c': set(['amiga', 'atari', 'coleco', 'dendy']), 'd': set(['atari', 'coleco', 'dendy']), }, } oses = set(['amiga', 'atari', 'coleco', 'dendy']) expected_values = { 'command': { ('echo', 'Hello World'): set(['atari']), ('echo', 'You should get an Atari'): set(['!atari']), }, KEY_TRACKED: { 'a': set([None]), 'b': set(['!dendy']), }, KEY_UNTRACKED: { 'c': set([None]), 'd': set(['!atari']), }, KEY_TOUCHED: { 'b': set(['dendy']), 'd': set(['atari']), }, 'read_only': {}, } actual_values, actual_oses = isolate.reduce_inputs(values, oses) self.assertEquals(expected_values, actual_values) self.assertEquals(oses, actual_oses)
def test_reduce_inputs_take_strongest_dependency(self): amiga, atari, coleco, dendy = ( set([(os,)]) for os in ('amiga', 'atari', 'coleco', 'dendy')) values = { 'command': { ('echo', 'Hello World'): atari, ('echo', 'You should get an Atari'): amiga | coleco | dendy, }, KEY_TRACKED: { 'a': amiga | atari | coleco | dendy, 'b': amiga | atari | coleco, }, KEY_UNTRACKED: { 'c': amiga | atari | coleco | dendy, 'd': amiga | coleco | dendy, }, KEY_TOUCHED: { 'a': amiga | atari | coleco | dendy, 'b': atari | coleco | dendy, 'c': amiga | atari | coleco | dendy, 'd': atari | coleco | dendy, }, } expected_values = { 'command': { ('echo', 'Hello World'): atari, ('echo', 'You should get an Atari'): amiga | coleco | dendy, }, KEY_TRACKED: { 'a': amiga | atari | coleco | dendy, 'b': amiga | atari | coleco, }, KEY_UNTRACKED: { 'c': amiga | atari | coleco | dendy, 'd': amiga | coleco | dendy, }, KEY_TOUCHED: { 'b': dendy, 'd': atari, }, 'read_only': {}, } actual_values = isolate.reduce_inputs(values) self.assertEqual(expected_values, actual_values)
def main(args=None): parser = run_test_cases.OptionParserWithLogging( usage='%prog <options> [file1] [file2] ...') parser.add_option( '-o', '--output', help='Output to file instead of stdout') parser.add_option( '--os', default=','.join(DEFAULT_OSES), help='Inject the list of OSes, default: %default') options, args = parser.parse_args(args) configs = load_isolates(args, options.os.split(',')) data = convert_map_to_isolate_dict( *reduce_inputs(*invert_map(configs.flatten()))) if options.output: with open(options.output, 'wb') as f: print_all(configs.file_comment, data, f) else: print_all(configs.file_comment, data, sys.stdout) return 0
def test_reduce_inputs_merge_subfolders_and_files(self): values = { 'command': {}, KEY_TRACKED: { 'folder/tracked_file': set(['win']), 'folder_helper/tracked_file': set(['win']), }, KEY_UNTRACKED: { 'folder/': set(['linux', 'mac', 'win']), 'folder/subfolder/': set(['win']), 'folder/untracked_file': set(['linux', 'mac', 'win']), 'folder_helper/': set(['linux']), }, KEY_TOUCHED: { 'folder/touched_file': set (['win']), 'folder/helper_folder/deep_file': set(['win']), 'folder_helper/touched_file1': set (['mac', 'win']), 'folder_helper/touched_file2': set (['linux']), }, } oses = set(['linux', 'mac', 'win']) expected_values = { 'command': {}, KEY_TRACKED: { 'folder_helper/tracked_file': set(['win']), }, KEY_UNTRACKED: { 'folder/': set([None]), 'folder_helper/': set(['linux']), }, KEY_TOUCHED: { 'folder_helper/touched_file1': set (['!linux']), }, 'read_only': {}, } actual_values, actual_oses = isolate.reduce_inputs(values, oses) self.assertEqual(expected_values, actual_values) self.assertEqual(oses, actual_oses)
def test_reduce_inputs_merge_subfolders_and_files(self): linux, mac, win = (set([(os,)]) for os in ('linux', 'mac', 'win')) values = { KEY_TRACKED: { 'folder/tracked_file': win, 'folder_helper/tracked_file': win, }, KEY_UNTRACKED: { 'folder/': linux | mac | win, 'folder/subfolder/': win, 'folder/untracked_file': linux | mac | win, 'folder_helper/': linux, }, KEY_TOUCHED: { 'folder/touched_file': win, 'folder/helper_folder/deep_file': win, 'folder_helper/touched_file1': mac | win, 'folder_helper/touched_file2': linux, }, } expected_values = { 'command': {}, KEY_TRACKED: { 'folder_helper/tracked_file': win, }, KEY_UNTRACKED: { 'folder/': linux | mac | win, 'folder_helper/': linux, }, KEY_TOUCHED: { 'folder_helper/touched_file1': mac | win, }, 'read_only': {}, } actual_values = isolate.reduce_inputs(values) self.assertEqual(expected_values, actual_values)
def test_merge_empty(self): actual = isolate.convert_map_to_isolate_dict( isolate.reduce_inputs(isolate.invert_map({})), ('dummy1', 'dummy2')) self.assertEqual({'conditions': []}, actual)
def test_reduce_inputs(self): amiga, atari, coleco, dendy = ( set([(os,)]) for os in ('amiga', 'atari', 'coleco', 'dendy')) values = { 'command': { ('echo', 'Hello World'): atari, ('echo', 'You should get an Atari'): amiga | coleco | dendy, }, KEY_TRACKED: { 'a': amiga | atari | coleco | dendy, 'c': atari, 'e': amiga | coleco | dendy, 'g': amiga, 'x': amiga | atari | coleco | dendy, }, KEY_UNTRACKED: { 'b': amiga | atari | coleco | dendy, 'd': atari, 'f': amiga | coleco | dendy, 'h': amiga | atari | dendy, }, KEY_TOUCHED: { 'touched': amiga | atari | coleco | dendy, 'touched_a': atari, 'touched_e': amiga | coleco | dendy, }, 'read_only': { False: amiga, True: atari, }, } expected_values = { 'command': { ('echo', 'Hello World'): atari, ('echo', 'You should get an Atari'): amiga | coleco | dendy, }, KEY_TRACKED: { 'a': amiga | atari | coleco | dendy, 'c': atari, 'e': amiga | coleco | dendy, 'g': amiga, 'x': amiga | atari | coleco | dendy, }, KEY_UNTRACKED: { 'b': amiga | atari | coleco | dendy, 'd': atari, 'f': amiga | coleco | dendy, 'h': amiga | atari | dendy, }, KEY_TOUCHED: { 'touched': amiga | atari | coleco | dendy, 'touched_a': atari, 'touched_e': amiga | coleco | dendy, }, 'read_only': { False: amiga, True: atari, }, } actual_values = isolate.reduce_inputs(values) self.assertEqual(expected_values, actual_values)
def test_merge_empty(self): actual = isolate.convert_map_to_isolate_dict( *isolate.reduce_inputs(*isolate.invert_map({}))) self.assertEquals({}, actual)
def test_reduce_inputs(self): values = { 'command': { ('echo', 'Hello World'): set(['atari']), ('echo', 'You should get an Atari'): set(['amiga', 'coleco', 'dendy']), }, KEY_TRACKED: { 'a': set(['amiga', 'atari', 'coleco', 'dendy']), 'c': set(['atari']), 'e': set(['amiga', 'coleco', 'dendy']), 'g': set(['amiga']), 'x': set(['amiga', 'atari', 'coleco', 'dendy']), }, KEY_UNTRACKED: { 'b': set(['amiga', 'atari', 'coleco', 'dendy']), 'd': set(['atari']), 'f': set(['amiga', 'coleco', 'dendy']), 'h': set(['amiga', 'atari', 'dendy']), }, KEY_TOUCHED: { 'touched': set(['amiga', 'atari', 'coleco', 'dendy']), 'touched_a': set(['atari']), 'touched_e': set(['amiga', 'coleco', 'dendy']), }, 'read_only': { None: set(['coleco', 'dendy']), False: set(['amiga']), True: set(['atari']), }, } oses = set(['amiga', 'atari', 'coleco', 'dendy']) expected_values = { 'command': { ('echo', 'Hello World'): set(['atari']), ('echo', 'You should get an Atari'): set(['!atari']), }, KEY_TRACKED: { 'a': set([None]), 'c': set(['atari']), 'e': set(['!atari']), 'g': set(['amiga']), 'x': set([None]), }, KEY_UNTRACKED: { 'b': set([None]), 'd': set(['atari']), 'f': set(['!atari']), 'h': set(['!coleco']), }, KEY_TOUCHED: { 'touched': set([None]), 'touched_a': set(['atari']), 'touched_e': set(['!atari']), }, 'read_only': { None: set(['coleco', 'dendy']), False: set(['amiga']), True: set(['atari']), }, } actual_values, actual_oses = isolate.reduce_inputs(values, oses) self.assertEquals(expected_values, actual_values) self.assertEquals(oses, actual_oses)