def test_load_three_conditions(self): linux = { 'conditions': [ ['OS=="linux"', { 'variables': { 'isolate_dependency_tracked': [ 'file_linux', 'file_common', ], }, }], ], } mac = { 'conditions': [ ['OS=="mac"', { 'variables': { 'isolate_dependency_tracked': [ 'file_mac', 'file_common', ], }, }], ], } win = { 'conditions': [ ['OS=="win"', { 'variables': { 'isolate_dependency_tracked': [ 'file_win', 'file_common', ], }, }], ], } expected = { 'linux': { 'isolate_dependency_tracked': ['file_common', 'file_linux'], }, 'mac': { 'isolate_dependency_tracked': ['file_common', 'file_mac'], }, 'win': { 'isolate_dependency_tracked': ['file_common', 'file_win'], }, } # Pylint is confused about union() return type. # pylint: disable=E1103 configs = isolate.union( isolate.union( isolate.union( isolate.Configs([], None), isolate.load_isolate_as_config(linux, None, [])), isolate.load_isolate_as_config(mac, None, [])), isolate.load_isolate_as_config(win, None, [])).flatten() self.assertEquals(expected, configs)
def test_load_three_conditions(self): linux = { 'conditions': [ ['OS=="linux" and chromeos==1', { 'variables': { 'isolate_dependency_tracked': [ 'file_linux', 'file_common', ], }, }], ], } mac = { 'conditions': [ ['OS=="mac" and chromeos==0', { 'variables': { 'isolate_dependency_tracked': [ 'file_mac', 'file_common', ], }, }], ], } win = { 'conditions': [ ['OS=="win" and chromeos==0', { 'variables': { 'isolate_dependency_tracked': [ 'file_win', 'file_common', ], }, }], ], } expected = { ('linux', 1): { 'isolate_dependency_tracked': ['file_common', 'file_linux'], }, ('mac', 0): { 'isolate_dependency_tracked': ['file_common', 'file_mac'], }, ('win', 0): { 'isolate_dependency_tracked': ['file_common', 'file_win'], }, } # Pylint is confused about union() return type. # pylint: disable=E1103 configs = isolate.union( isolate.union( isolate.union( isolate.Configs(None), isolate.load_isolate_as_config(self.cwd, linux, None)), isolate.load_isolate_as_config(self.cwd, mac, None)), isolate.load_isolate_as_config(self.cwd, win, None)).flatten() self.assertEqual(expected, configs)
def test_merge_two_empty(self): # Flat stay flat. Pylint is confused about union() return type. # pylint: disable=E1103 actual = isolate.union( isolate.union( isolate.Configs(None), isolate.load_isolate_as_config(self.cwd, {}, None)), isolate.load_isolate_as_config(self.cwd, {}, None)).flatten() self.assertEqual({}, actual)
def load_isolates(items): """Parses each .isolate file and returns the merged results. It only loads what load_isolate_as_config() can process. Return values: files: dict(filename, set(OS where this filename is a dependency)) dirs: dict(dirame, set(OS where this dirname is a dependency)) oses: set(all the OSes referenced) """ configs = None for item in items: item = os.path.abspath(item) logging.debug('loading %s' % item) if item == '-': content = sys.stdin.read() else: with open(item, 'r') as f: content = f.read() new_config = load_isolate_as_config( os.path.dirname(item), eval_content(content), extract_comment(content)) logging.debug('has configs: ' + ','.join(map(repr, new_config.by_config))) configs = union(configs, new_config) logging.debug('Total configs: ' + ','.join(map(repr, configs.by_config))) return configs
def load_isolates(items): """Parses each .isolate file and returns the merged results. It only loads what load_isolate_as_config() can process. Return values: files: dict(filename, set(OS where this filename is a dependency)) dirs: dict(dirame, set(OS where this dirname is a dependency)) oses: set(all the OSes referenced) """ configs = None for item in items: item = os.path.abspath(item) logging.debug('loading %s' % item) if item == '-': content = sys.stdin.read() else: with open(item, 'r') as f: content = f.read() new_config = load_isolate_as_config(os.path.dirname(item), eval_content(content), extract_comment(content)) logging.debug('has configs: ' + ','.join(map(repr, new_config.by_config))) configs = union(configs, new_config) logging.debug('Total configs: ' + ','.join(map(repr, configs.by_config))) return configs
def test_configs_comment(self): # Pylint is confused with isolate.union() return type. # pylint: disable=E1103 configs = isolate.union( isolate.load_isolate_as_config({}, '# Yo dawg!\n# Chill out.\n', []), isolate.load_isolate_as_config({}, None, [])) self.assertEquals('# Yo dawg!\n# Chill out.\n', configs.file_comment) configs = isolate.union( isolate.load_isolate_as_config({}, None, []), isolate.load_isolate_as_config({}, '# Yo dawg!\n# Chill out.\n', [])) self.assertEquals('# Yo dawg!\n# Chill out.\n', configs.file_comment) # Only keep the first one. configs = isolate.union( isolate.load_isolate_as_config({}, '# Yo dawg!\n', []), isolate.load_isolate_as_config({}, '# Chill out.\n', [])) self.assertEquals('# Yo dawg!\n', configs.file_comment)
def test_union(self): value1 = { 'a': set(['A']), 'b': ['B', 'C'], 'c': 'C', } value2 = { 'a': set(['B', 'C']), 'b': [], 'd': set(), } expected = { 'a': set(['A', 'B', 'C']), 'b': ['B', 'C'], 'c': 'C', 'd': set(), } self.assertEqual(expected, isolate.union(value1, value2))
def load_isolates(items, default_oses): """Parses each .isolate file and returns the merged results. It only loads what load_isolate_as_config() can process. Return values: files: dict(filename, set(OS where this filename is a dependency)) dirs: dict(dirame, set(OS where this dirname is a dependency)) oses: set(all the OSes referenced) """ configs = Configs(default_oses, None) for item in items: logging.debug('loading %s' % item) with open(item, 'r') as f: content = f.read() new_config = load_isolate_as_config( eval_content(content), extract_comment(content), default_oses) logging.debug('has OSes: %s' % ','.join(k for k in new_config.per_os if k)) configs = union(configs, new_config) logging.debug('Total OSes: %s' % ','.join(k for k in configs.per_os if k)) return configs