Merge pull request #318 from GladysNalvarte/test_images

Checks if the environment.yml file is empty and if it contains a dict…
pull/324/head
Chris Holdgraf 2018-06-05 23:43:56 +01:00 zatwierdzone przez GitHub
commit 2dc4874261
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 32 dodań i 0 usunięć

Wyświetl plik

@ -136,6 +136,12 @@ class CondaBuildPack(BaseImage):
py_version = None
with open(environment_yml) as f:
env = YAML().load(f)
# check if the env file is empty, if so instantiate an empty dictionary.
if env is None:
env = {}
# check if the env file has a dictionary not a list or other data structure.
if not isinstance(env, dict):
raise TypeError("environment.yml should contain a dictionary. Got %r" % type(env))
for dep in env.get('dependencies', []):
if not isinstance(dep, str):
continue

Wyświetl plik

@ -0,0 +1,26 @@
"""
Test if the environment.yml is empty or it constains other data structure than a dictionary
"""
import os
import sys
import pytest
from repo2docker import buildpacks
def test_empty_env_yml(tmpdir):
tmpdir.chdir()
p = tmpdir.join("environment.yml")
p.write("")
bp = buildpacks.CondaBuildPack()
py_ver = bp.python_version
# If the environment.yml is empty python_version will get an empty string
assert py_ver == ''
def test_no_dict_env_yml(tmpdir):
tmpdir.chdir()
q = tmpdir.join("environment.yml")
q.write("numpy\n "
"matplotlib\n")
bq = buildpacks.CondaBuildPack()
with pytest.raises(TypeError):
py_ver = bq.python_version