def test_load_yaml_git(): r"""Test loading a yaml from a remote git repository.""" yml = "https://github.com/cropsinsilico/example-fakemodel/fakemodel.yml" assert_raises(Exception, yamlfile.load_yaml, yml) assert('model' in yamlfile.load_yaml('git:' + yml)) yml = "cropsinsilico/example-fakemodel/fakemodel.yml" assert('model' in yamlfile.load_yaml('git:' + yml))
def test_load_yaml(): r"""Test loading yaml.""" cwd = os.getcwd() fname = os.path.join(cwd, 'test_load_yaml.yml') dict_write = {'test': 'hello'} dict_read = {'test': 'hello', 'working_dir': cwd} contents = yaml.dump(dict_write) with open(fname, 'w') as fd: yaml.dump(dict_write, fd) try: # Dictionary out = yamlfile.load_yaml(dict_write) assert_equal(out, dict_read) # File name out = yamlfile.load_yaml(fname) assert_equal(out, dict_read) # Open file object with open(fname, 'r') as fd: out = yamlfile.load_yaml(fd) assert_equal(out, dict_read) # Open stream out = yamlfile.load_yaml(sio.StringIO(contents)) assert_equal(out, dict_read) finally: # Remove file if os.path.isfile(fname): os.remove(fname)
def test_load_yaml_git(): r"""Test loading a yaml from a remote git repository.""" import git yml = "https://github.com/cropsinsilico/example-fakemodel/fakemodel.yml" with pytest.raises(Exception): yamlfile.load_yaml(yml) assert ('model' in yamlfile.load_yaml('git:' + yml)) yml = "cropsinsilico/example-fakemodel/fakemodel.yml" assert ('model' in yamlfile.load_yaml('git:' + yml)) git.rmtree("cropsinsilico")
def test_load_yaml_git(self): yml = "https://github.com/cropsinsilico/example-fakemodel/fakemodel.yml" self.assertRaises(Exception, yamlfile.load_yaml, yml) self.assertTrue('model' in yamlfile.load_yaml('git:' + yml)) yml = "cropsinsilico/example-fakemodel/fakemodel.yml" self.assertTrue('model' in yamlfile.load_yaml('git:' + yml))
def test_load_yaml_error(): r"""Test error on loading invalid file.""" with pytest.raises(IOError): yamlfile.load_yaml('invalid')