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_format.convert_map_to_isolate_dict(
       isolate_format.reduce_inputs(isolate_format.invert_map(values)),
       ('OS',))
   self.assertEqual(expected, actual)
 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_format.reduce_inputs(values)
   self.assertEqual(expected_values, actual_values)
 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_format.reduce_inputs(values)
   self.assertEqual(expected_values, actual_values)
 def test_merge_empty(self):
   actual = isolate_format.convert_map_to_isolate_dict(
       isolate_format.reduce_inputs(isolate_format.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': {
       0: amiga,
       1: 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': {
       0: amiga,
       1: atari,
     },
   }
   actual_values = isolate_format.reduce_inputs(values)
   self.assertEqual(expected_values, actual_values)