Skip to content

Commit

Permalink
Add basic install tests
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Mar 25, 2015
1 parent 15441c0 commit 6ed7788
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
3 changes: 3 additions & 0 deletions tests/samples/package1-pkg.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
author=Sir Robin
author-email=robin@camelot.uk
home-page=http://github.com/sirrobin/package1

[scripts]
pkg_script=package1:main
3 changes: 3 additions & 0 deletions tests/samples/package1/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""A sample package"""

__version__ = '0.1'

def main():
print("package1 main")
54 changes: 54 additions & 0 deletions tests/test_install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import os
import pathlib
import tempfile
from unittest import TestCase
from unittest.mock import patch

from testpath import assert_isfile, assert_isdir, assert_islink

from flit import Importable
from flit.install import Installer

class InstallTests(TestCase):
def setUp(self):
self.orig_working_dir = os.getcwd()
samples_dir = os.path.join(os.path.dirname(__file__), 'samples')
os.chdir(samples_dir)

td = tempfile.TemporaryDirectory()
scripts_dir = os.path.join(td.name, 'scripts')
os.mkdir(scripts_dir)
purelib_dir = os.path.join(td.name, 'site-packages')
os.mkdir(purelib_dir)
self.addCleanup(td.cleanup)
self.get_dirs_patch = patch('flit.install.get_dirs',
return_value={'scripts': scripts_dir, 'purelib': purelib_dir})
self.get_dirs_patch.start()
self.tmpdir = pathlib.Path(td.name)

def tearDown(self):
self.get_dirs_patch.stop()
os.chdir(self.orig_working_dir)

def test_install_module(self):
i = Importable('module1')
i.check()
Installer(i).install()
assert_isfile(str(self.tmpdir / 'site-packages' / 'module1.py'))
assert_isdir(str(self.tmpdir / 'site-packages' / 'module1-0.1.egg-info'))

def test_install_package(self):
i = Importable('package1')
i.check()
Installer(i).install()
assert_isdir(str(self.tmpdir / 'site-packages' / 'package1'))
assert_isdir(str(self.tmpdir / 'site-packages' / 'package1-0.1.egg-info'))
assert_isfile(str(self.tmpdir / 'scripts' / 'pkg_script'))

def test_symlink_package(self):
i = Importable('package1')
i.check()
Installer(i, symlink=True).install()
assert_islink(str(self.tmpdir / 'site-packages' / 'package1'),
to=str(i.path.resolve()))
assert_isfile(str(self.tmpdir / 'scripts' / 'pkg_script'))
2 changes: 1 addition & 1 deletion tests/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from flit import Importable, wheel

class ImportableTests(TestCase):
class WheelTests(TestCase):
def setUp(self):
self.orig_working_dir = os.getcwd()
samples_dir = os.path.join(os.path.dirname(__file__), 'samples')
Expand Down

0 comments on commit 6ed7788

Please sign in to comment.