2020-12-28 20:14:39 +01:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
from pathlib import Path
|
|
|
|
|
2022-08-12 17:56:02 +02:00
|
|
|
import tomli
|
2022-09-15 11:42:01 +02:00
|
|
|
from django_tools.unittest_utils.project_setup import check_editor_config
|
2020-12-28 20:14:39 +01:00
|
|
|
|
2022-09-19 08:34:44 +02:00
|
|
|
import django_yunohost_integration
|
|
|
|
|
2020-12-28 20:14:39 +01:00
|
|
|
|
2021-02-28 10:56:42 +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} !')
|
|
|
|
|
|
|
|
|
2021-02-28 10:56:42 +01:00
|
|
|
def test_version():
|
2022-09-19 08:34:44 +02:00
|
|
|
upstream_version = django_yunohost_integration.__version__
|
|
|
|
|
2022-08-12 17:56:02 +02:00
|
|
|
pyproject_toml_path = Path(PACKAGE_ROOT, 'pyproject.toml')
|
|
|
|
pyproject_toml = tomli.loads(pyproject_toml_path.read_text(encoding='UTF-8'))
|
2022-09-19 08:34:44 +02:00
|
|
|
pyproject_version = pyproject_toml['tool']['poetry']['version']
|
|
|
|
assert pyproject_version.startswith(f'{upstream_version}+ynh')
|
|
|
|
|
|
|
|
# pyproject.toml needs a PEP 440 conform version and used "+ynh"
|
|
|
|
# the YunoHost syntax is: "~ynh", just "convert this:
|
|
|
|
manifest_version = pyproject_version.replace('+', '~')
|
2020-12-28 20:14:39 +01:00
|
|
|
|
2022-08-12 17:56:02 +02:00
|
|
|
assert_file_contains_string(
|
|
|
|
file_path=Path(PACKAGE_ROOT, 'manifest.json'),
|
2022-09-19 08:34:44 +02:00
|
|
|
string=f'"version": "{manifest_version}"',
|
2022-08-12 17:56:02 +02:00
|
|
|
)
|
2020-12-28 20:14:39 +01:00
|
|
|
|
|
|
|
|
2021-02-28 10:56:42 +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'],
|
2022-08-12 17:56:02 +02:00
|
|
|
text=True,
|
2020-12-28 20:14:39 +01:00
|
|
|
env=os.environ,
|
|
|
|
stderr=subprocess.STDOUT,
|
2021-02-28 10:56:42 +01:00
|
|
|
cwd=str(PACKAGE_ROOT),
|
2020-12-28 20:14:39 +01:00
|
|
|
)
|
|
|
|
print(output)
|
|
|
|
assert output == 'All set!\n'
|
2022-09-15 11:42:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_check_editor_config():
|
|
|
|
check_editor_config(package_root=PACKAGE_ROOT)
|