def test_empty_root_doesnt_effect_leaf(self): with TempDir() as d: root = os.path.join(d, 'tmp', '.needyconfig') leaf = os.path.join(d, 'tmp', 'dir', '.needyconfig') os.makedirs(os.path.dirname(leaf)) with open(root, 'w') as f: f.write(json.dumps({'build-caches': []})) with open(leaf, 'w') as f: f.write(json.dumps({'build-caches': ['foo']})) c = NeedyConfiguration(os.path.dirname(leaf)) self.assertEqual(len(c.build_caches()), 1)
def test_dict_and_list_paths(self): with TempDir() as d: path = os.path.join(d, 'tmp', 'dir', '.needyconfig') os.makedirs(os.path.dirname(path)) with open(path, 'w') as f: f.write(json.dumps({ 'build-caches': [ {'path': 'foo'}, {'path': 'bar'}, 'foobar', ] })) c = NeedyConfiguration(os.path.dirname(path)) self.assertEqual(len(c.build_caches()), 3)
def test_dict_and_list_paths(self): with TempDir() as d: path = os.path.join(d, 'tmp', 'dir', '.needyconfig') os.makedirs(os.path.dirname(path)) with open(path, 'w') as f: f.write( json.dumps({ 'build-caches': [ { 'path': 'foo' }, { 'path': 'bar' }, 'foobar', ] })) c = NeedyConfiguration(os.path.dirname(path)) self.assertEqual(len(c.build_caches()), 3)
def test_render(self): self.fs.CreateFile('needs.json', contents=textwrap.dedent('''\ libraries: mylib: {% set bar = 'bar' -%} directory: {{bar}} ''')) needy = Needy(needy_configuration=NeedyConfiguration(None)) self.assertEqual( needy.render().strip(), textwrap.dedent('''\ libraries: mylib: directory: bar ''').strip())
def test_libraries_to_build(self): self.fs.CreateFile('needs.json', contents=json.dumps({ 'libraries': { 'excluded': {}, 'dependant': { 'dependencies': 'dependency' }, 'dependency': {} } })) needy = Needy(needy_configuration=NeedyConfiguration(None)) libraries = needy.libraries_to_build(needy.target('host'), ['dependant']) self.assertEqual(len(libraries), 2) self.assertEqual(libraries[0][0], 'dependency') self.assertEqual(libraries[1][0], 'dependant')
def test_config_merging(self): with TempDir() as d: root = os.path.join(d, 'tmp', '.needyconfig') leaf = os.path.join(d, 'tmp', 'dir', '.needyconfig') os.makedirs(os.path.dirname(leaf)) with open(root, 'w') as f: f.write(json.dumps({'build-caches': ['bar']})) with open(leaf, 'w') as f: f.write(json.dumps({'build-caches': ['foo']})) c = NeedyConfiguration(os.path.dirname(leaf)) self.assertEqual(len(c.build_caches()), 2) self.assertEqual(c.build_caches()[0].cache().to_dict()['path'], 'foo') self.assertEqual(c.build_caches()[1].cache().to_dict()['path'], 'bar') c = NeedyConfiguration(os.path.dirname(root)) self.assertEqual(len(c.build_caches()), 1) self.assertEqual(c.build_caches()[0].cache().to_dict()['path'], 'bar')
def test_recursive_merge(self): d = {'build-caches': [{'path': 'foo'}]} NeedyConfiguration._recursive_merge(d, {'build-caches': ['bar']}) NeedyConfiguration._recursive_merge(d, {'build-caches': []}) self.assertEqual(d, {'build-caches': [{'path': 'foo'}, 'bar']})