mirror of
https://github.com/YunoHost-Apps/django_example_ynh.git
synced 2024-09-03 18:26:21 +02:00
+test_project_setup.py
This commit is contained in:
parent
0c4bf1e8de
commit
03a87bf63f
1 changed files with 54 additions and 0 deletions
54
tests/test_project_setup.py
Normal file
54
tests/test_project_setup.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
import django_ynh
|
||||
|
||||
|
||||
PACKAGE_ROOT = Path(django_ynh.__file__).parent.parent
|
||||
|
||||
|
||||
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(package_root=None, version=None):
|
||||
if package_root is None:
|
||||
package_root = PACKAGE_ROOT
|
||||
|
||||
if version is None:
|
||||
version = django_ynh.__version__
|
||||
|
||||
if 'dev' not in version and 'rc' not in version:
|
||||
version_string = f'v{version}'
|
||||
|
||||
assert_file_contains_string(file_path=Path(package_root, 'README.md'), string=version_string)
|
||||
|
||||
assert_file_contains_string(file_path=Path(package_root, 'pyproject.toml'), string=f'version = "{version}"')
|
||||
assert_file_contains_string(file_path=Path(package_root, 'manifest.json'), string=f'"version": "{version}~ynh",')
|
||||
|
||||
assert_file_contains_string(
|
||||
file_path=Path(package_root, 'deployment', 'project.env'), string=f'PROJECT_VERSION={version}'
|
||||
)
|
||||
|
||||
|
||||
def test_poetry_check(package_root=None):
|
||||
if package_root is None:
|
||||
package_root = PACKAGE_ROOT
|
||||
|
||||
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),
|
||||
)
|
||||
print(output)
|
||||
assert output == 'All set!\n'
|
Loading…
Add table
Reference in a new issue