43 lines
1.7 KiB
Python
43 lines
1.7 KiB
Python
from pathlib import Path
|
|
from shutil import rmtree
|
|
from subprocess import STDOUT, check_output
|
|
from tarfile import TarInfo
|
|
from tarfile import open as tar_open
|
|
from unittest.case import TestCase
|
|
|
|
try:
|
|
# OSX Homebrew fix: https://stackoverflow.com/a/53190037/1067833
|
|
from sys import _base_executable as executable
|
|
except ImportError:
|
|
from sys import executable
|
|
|
|
|
|
class InstallTest(TestCase):
|
|
'Testing package installation.'
|
|
|
|
def test_datadir_is_in_place(self):
|
|
'Data directory should be in the virtualenv *after installation*.'
|
|
output = check_output([
|
|
executable, '-c', (
|
|
'import sys;sys.path.remove("");import validate_email;' +
|
|
'print(validate_email.updater.BLACKLIST_FILEPATH_INSTALLED);' +
|
|
'print(validate_email.updater.ETAG_FILEPATH_INSTALLED, end="")'
|
|
)]).decode('ascii')
|
|
bl_path, etag_path = output.split('\n')
|
|
self.assertTrue(
|
|
expr=Path(bl_path).exists(), msg=f'{bl_path!r} doesn\'t exist.')
|
|
self.assertTrue(
|
|
expr=Path(etag_path).exists(),
|
|
msg=f'{etag_path!r} doesn\'t exist.')
|
|
|
|
def test_sdist_excludes_datadir(self):
|
|
'The created sdist should not contain the data dir.'
|
|
check_output(
|
|
args=[executable, 'setup.py', '-q', 'sdist'], stderr=STDOUT)
|
|
latest_sdist = list(Path('dist').glob(pattern='*.tar.gz'))[-1]
|
|
tar_file = tar_open(name=latest_sdist, mode='r:gz')
|
|
for tarinfo in tar_file: # type: TarInfo
|
|
self.assertNotIn(
|
|
member='/validate_email/data/', container=tarinfo.name)
|
|
# Clean up after the test
|
|
rmtree('dist')
|