django_example_ynh/tests/test_project_setup.py

40 lines
1.1 KiB
Python
Raw Normal View History

2020-12-28 20:14:39 +01:00
import os
import shutil
import subprocess
from pathlib import Path
2021-09-15 19:16:35 +02:00
import django_yunohost_integration
2020-12-28 20:14:39 +01:00
PACKAGE_ROOT = Path(__file__).parent.parent
2020-12-28 20:14:39 +01:00
def assert_file_contains_string(file_path, string):
with file_path.open('r') as f:
for line in f:
if string in line:
return
raise AssertionError(f'File {file_path} does not contain {string!r} !')
def test_version():
2021-09-15 19:16:35 +02:00
version = django_yunohost_integration.__version__
2020-12-28 20:14:39 +01:00
assert_file_contains_string(file_path=Path(PACKAGE_ROOT, 'pyproject.toml'), string=f'version = "{version}~ynh')
2021-09-15 19:16:35 +02:00
assert_file_contains_string(file_path=Path(PACKAGE_ROOT, 'pyproject.toml'), string=f'django_yunohost_integration = "=={version}"')
assert_file_contains_string(file_path=Path(PACKAGE_ROOT, 'manifest.json'), string=f'"version": "{version}~ynh')
2020-12-28 20:14:39 +01:00
def test_poetry_check():
2020-12-28 20:14:39 +01:00
poerty_bin = shutil.which('poetry')
output = subprocess.check_output(
[poerty_bin, 'check'],
universal_newlines=True,
env=os.environ,
stderr=subprocess.STDOUT,
cwd=str(PACKAGE_ROOT),
2020-12-28 20:14:39 +01:00
)
print(output)
assert output == 'All set!\n'