Skip to content

Commit

Permalink
tests: Add test_distribution. See #214
Browse files Browse the repository at this point in the history
  • Loading branch information
jcfr committed Nov 24, 2016
1 parent e62da60 commit 60a2f61
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
1 change: 1 addition & 0 deletions requirements-dev.txt
Expand Up @@ -6,4 +6,5 @@ pytest==3.0.3
pytest-cov==2.4.0
pytest-mock==1.4.0
pytest-runner==2.9
pytest-virtualenv==1.2.4
six==1.10.0
15 changes: 10 additions & 5 deletions tests/__init__.py
Expand Up @@ -124,6 +124,9 @@ def initialize_git_repo_and_commit(project_dir, verbose=True):
git repository with one commit containing all the directories and files
is created.
"""
if isinstance(project_dir, six.string_types):
project_dir = py.path.local(project_dir)

if project_dir.join('.git').exists():
return

Expand All @@ -140,23 +143,25 @@ def initialize_git_repo_and_commit(project_dir, verbose=True):
do_call(cmd)


def prepare_project(project, tmp_project_dir):
def prepare_project(project, tmp_project_dir, force=False):
"""Convenience function setting up the build directory ``tmp_project_dir``
for the selected sample ``project``.
If ``tmp_project_dir`` does not exist, it is created.
If ``tmp_project_dir`` is empty, the sample ``project`` is copied into it.
Specifying ``force=True`` will copy the files even if ``tmp_project_dir``
is not empty.
"""

tmp_project_dir = py.path.local(tmp_project_dir)
if isinstance(tmp_project_dir, six.string_types):
tmp_project_dir = py.path.local(tmp_project_dir)

# Create project directory if it does not exist
if not tmp_project_dir.exists():
tmp_project_dir = _tmpdir(project)

# If empty, copy project files and initialize git
if not tmp_project_dir.listdir():
# If empty or if force is True, copy project files and initialize git
if not tmp_project_dir.listdir() or force:
_copy_dir(tmp_project_dir, os.path.join(SAMPLES_DIR, project))


Expand Down
39 changes: 39 additions & 0 deletions tests/test_distribution.py
@@ -0,0 +1,39 @@

import os
import pytest

from path import Path

from . import initialize_git_repo_and_commit, prepare_project

DIST_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '../dist'))


def test_source_distribution(virtualenv):
sdists = Path(DIST_DIR).files(pattern="*.tar.gz")
if not sdists:
pytest.skip("no source distribution available")
assert len(sdists) == 1

virtualenv.run("pip install %s" % sdists[0])
assert "scikit-build" in virtualenv.installed_packages()

prepare_project("hello", virtualenv.workspace, force=True)
initialize_git_repo_and_commit(virtualenv.workspace, verbose=False)

virtualenv.run("python setup.py bdist_wheel")


def test_wheel(virtualenv):
wheels = Path(DIST_DIR).files(pattern="*.whl")
if not wheels:
pytest.skip("no wheel available")
assert len(wheels) == 1

virtualenv.run("pip install %s" % wheels[0])
assert "scikit-build" in virtualenv.installed_packages()

prepare_project("hello", virtualenv.workspace, force=True)
initialize_git_repo_and_commit(virtualenv.workspace, verbose=False)

virtualenv.run("python setup.py bdist_wheel")

0 comments on commit 60a2f61

Please sign in to comment.