kopia lustrzana https://github.com/jupyterhub/repo2docker
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
commit
2dc4874261
|
@ -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
|
||||
|
|
|
@ -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
|
Ładowanie…
Reference in New Issue