kopia lustrzana https://github.com/jupyterhub/repo2docker
Checks if the environment.yml file is empty and if it contains a dictionary.
If the environment.yml is empty, an empty dictionary is instantiated. This will rise an TypeError if the environment.yml file contains a list or other data structure different than a dictionary.pull/318/head
rodzic
a6c001a391
commit
709ac4c757
|
@ -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" % env)
|
||||
for dep in env.get('dependencies', []):
|
||||
if not isinstance(dep, str):
|
||||
continue
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
"""
|
||||
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
|
||||
|
||||
#@pytest.mark.xfail(reason="Not yet implemented")
|
||||
def test_empty_env_yml(tmpdir):
|
||||
tmpdir.chdir()
|
||||
p = tmpdir.join("environment.yml")
|
||||
bp = buildpacks.CondaBuildPack()
|
||||
with pytest.raises(Exception):
|
||||
py_ver = bp.python_version()
|
||||
|
||||
def test_no_dict_env_yml(tmpdir):
|
||||
tmpdir.chdir()
|
||||
q = tmpdir.join("environment.yml")
|
||||
q.write("list/n ,string")
|
||||
bq = buildpacks.CondaBuildPack()
|
||||
with pytest.raises(Exception):
|
||||
py_ver = bq.python_version()
|
Ładowanie…
Reference in New Issue