Skip to content

Commit

Permalink
unit test fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Kale Franz <[email protected]>
  • Loading branch information
kalefranz committed Sep 3, 2018
1 parent 5d254aa commit 3cd00a3
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 34 deletions.
18 changes: 9 additions & 9 deletions conda/core/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ def __init__(self, *setups):
self.prefix_action_groups = odict()

for stp in itervalues(self.prefix_setups):
log.debug("instantiating UnlinkLinkTransaction with\n"
" target_prefix: %s\n"
" unlink_precs:\n"
" %s\n"
" link_precs:\n"
" %s\n",
stp.target_prefix,
'\n '.join(prec.dist_str() for prec in stp.unlink_precs),
'\n '.join(prec.dist_str() for prec in stp.link_precs))
log.info("initializing UnlinkLinkTransaction with\n"
" target_prefix: %s\n"
" unlink_precs:\n"
" %s\n"
" link_precs:\n"
" %s\n",
stp.target_prefix,
'\n '.join(prec.dist_str() for prec in stp.unlink_precs),
'\n '.join(prec.dist_str() for prec in stp.link_precs))

self._pfe = None
self._prepared = False
Expand Down
19 changes: 13 additions & 6 deletions conda/core/python_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from csv import reader as csv_reader
from email.parser import HeaderParser
from fnmatch import filter as fnmatch_filter
from logging import getLogger
from os import listdir
from os.path import basename, dirname, isdir, isfile, join, lexists, normpath
import re
Expand All @@ -18,6 +19,7 @@
from ..common.compat import PY2, StringIO, itervalues, odict, open
from ..common.path import (get_major_minor_version, get_python_site_packages_short_path, pyc_path,
win_path_ok)
from ..exceptions import PathNotFoundError
from ..models.channel import Channel
from ..models.enums import PackageType, PathType
from ..models.records import PathData, PathDataV1, PathsData, PrefixRecord
Expand All @@ -32,6 +34,7 @@
except ImportError: # pragma: no cover
from .._vendor.toolz.itertoolz import concat, concatv, groupby # NOQA

log = getLogger(__name__)

# TODO: complete this list
PYPI_TO_CONDA = {
Expand Down Expand Up @@ -80,8 +83,12 @@ def get_python_record(prefix_path, anchor_file, python_version):
Return `None` if the python record cannot be created.
"""
# TODO: ensure that this dist is actually the dist that matches conda-meta
pydist = get_python_distribution_info(prefix_path, anchor_file, python_version)
return None if pydist is None else pydist.prefix_record
try:
pydist = get_python_distribution_info(prefix_path, anchor_file, python_version)
return pydist.prefix_record
except PathNotFoundError as e:
log.debug("%r", e)
return None


# Python distribution/eggs metadata
Expand Down Expand Up @@ -468,8 +475,7 @@ def __init__(self, anchor_full_path, python_version):
elif anchor_full_path and isdir(anchor_full_path):
self._metadata_dir_full_path = anchor_full_path
else:
self._metadata_dir_full_path = None
raise RuntimeError("Path not found: %s", anchor_full_path)
raise RuntimeError("Path not found: %s" % anchor_full_path)

self._check_files()
self._metadata = PythonDistributionMetadata(anchor_full_path)
Expand Down Expand Up @@ -954,8 +960,6 @@ def get_site_packages_anchor_files(site_packages_path, site_packages_dir):
def get_dist_file_from_egg_link(egg_link_file, prefix_path):
"""
Return the egg info file path following an egg link.
Return `None` if no egg-info is found or the path is no longer there.
"""
egg_info_full_path = None

Expand All @@ -977,6 +981,9 @@ def get_dist_file_from_egg_link(egg_link_file, prefix_path):
if isdir(egg_info_full_path):
egg_info_full_path = join(egg_info_full_path, "PKG-INFO")

if egg_info_full_path is None:
raise PathNotFoundError(egg_link_contents)

return egg_info_full_path


Expand Down
21 changes: 12 additions & 9 deletions dev/start
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,24 @@ pyver="${2:-3}"

if ! [ -f "$devenv/conda-meta/history" ]; then
if [ "$(uname)" = Darwin ]; then
curl https://repo.anaconda.com/miniconda/Miniconda$pyver-latest-MacOSX-x86_64.sh -o miniconda.sh
if [ ! -f miniconda.sh ]; then
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -o miniconda.sh
fi
bash miniconda.sh -bfp "$devenv"
"$devenv/bin/conda" update -yq --all
"$devenv/bin/conda" install -yq --file dev/test-requirements.txt -c defaults -c conda-forge
"$devenv/bin/conda" install -yq python=$pyver --file dev/test-requirements.txt -c defaults -c conda-forge
elif [ "$(uname)" = Linux ]; then
curl https://repo.anaconda.com/miniconda/Miniconda$pyver-latest-Linux-x86_64.sh -o miniconda.sh
if [ ! -f miniconda3.sh ]; then
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -o miniconda.sh
fi
bash miniconda.sh -bfp "$devenv"
"$devenv/bin/conda" update -yq --all
"$devenv/bin/conda" install -yq --file dev/test-requirements.txt -c defaults -c conda-forge
"$devenv/bin/conda" install -yq python=$pyver --file dev/test-requirements.txt -c defaults -c conda-forge
"$devenv/bin/conda" install -yq patchelf # for conda-build
else
powershell.exe -Command "(new-object System.Net.WebClient).DownloadFile('https://repo.anaconda.com/miniconda/Miniconda$pyver-latest-Windows-x86_64.exe','miniconda.exe')"
if [ ! -f miniconda.exe ]; then
powershell.exe -Command "(new-object System.Net.WebClient).DownloadFile('https://repo.anaconda.com/miniconda/Miniconda$pyver-latest-Windows-x86_64.exe','miniconda.exe')"
fi
cmd.exe /c "start /wait \"\" miniconda.exe /InstallationType=JustMe /RegisterPython=0 /AddToPath=0 /S /D=%CD%\$(cygpath -w $devenv)"
"$devenv/Scripts/conda" update -yq --all
"$devenv/Scripts/conda" install -yq --file dev/test-requirements.txt -c defaults -c conda-forge
"$devenv/Scripts/conda" install -yq python=$pyver --file dev/test-requirements.txt -c defaults -c conda-forge
fi
fi

Expand Down
2 changes: 1 addition & 1 deletion dev/test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
flake8
mock
pexpect
pytest
pytest!=3.7.3
pytest-cov
pytest-timeout
conda-forge::radon
Expand Down
15 changes: 7 additions & 8 deletions tests/core/test_python_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""Test for python distribution information and metadata handling."""
from __future__ import absolute_import, division, print_function, unicode_literals

from conda.exceptions import PathNotFoundError
from contextlib import contextmanager
from datetime import datetime
import os
Expand Down Expand Up @@ -314,18 +315,16 @@ def test_get_dist_file_from_egg_link():

# Test not existing path
temp_path3, fpaths3 = _create_test_files((('', 'egg2.egg-link', '/not-a-path/'),))
output = pd.get_dist_file_from_egg_link(fpaths3[0], '')
expected_output = None
_print_output(output, expected_output)
assert output == expected_output
with pytest.raises(PathNotFoundError) as exc:
pd.get_dist_file_from_egg_link(fpaths3[0], '')
print(exc.value)

# Test existing path but no valig egg-info files
temp_path4 = tempfile.mkdtemp()
temp_path4, fpaths4 = _create_test_files((('', 'egg2.egg-link', temp_path4),))
output = pd.get_dist_file_from_egg_link(fpaths4[0], '')
expected_output = None
_print_output(output, expected_output)
assert output == expected_output
with pytest.raises(PathNotFoundError) as exc:
pd.get_dist_file_from_egg_link(fpaths4[0], '')
print(exc.value)


@pytest.mark.skipif(True, reason="Ask @goanpeca about what this test is looking for.")
Expand Down
2 changes: 1 addition & 1 deletion utils/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-r requirements.txt
flake8
mock
pytest
pytest!=3.7.3
pytest-cov
pytest-timeout
radon
Expand Down

0 comments on commit 3cd00a3

Please sign in to comment.