コード例 #1
0
ファイル: test_yamlfile.py プロジェクト: Xyzic/yggdrasil
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))
コード例 #2
0
ファイル: test_yamlfile.py プロジェクト: Xyzic/yggdrasil
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)
コード例 #3
0
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")
コード例 #4
0
 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))
コード例 #5
0
def test_load_yaml_error():
    r"""Test error on loading invalid file."""
    with pytest.raises(IOError):
        yamlfile.load_yaml('invalid')