Skip to content

Commit

Permalink
Improve the testing of test scripts (PR #906)
Browse files Browse the repository at this point in the history
  • Loading branch information
vxgmichel committed Jan 6, 2020
2 parents 9d42115 + 87d6fd5 commit fcfd802
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 11 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ addons:
apt:
packages:
- postgresql-server-dev-9.5
- desktop-file-utils
install:
- pip install -U wheel
- python setup.py bdist_wheel
Expand Down
3 changes: 1 addition & 2 deletions tests/scripts/run_testenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ elif [ -n "$ZSH_VERSION" ]; then
script_dir=$(dirname $(realpath -s $0))
fi


# Run python script and source
source_file=$(tempfile)
$script_dir/run_testenv.py --source-file $source_file $@
$script_dir/run_testenv.py --source-file $source_file $@ || return $?
source $source_file

# Clean up
Expand Down
74 changes: 65 additions & 9 deletions tests/test_scripts.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,72 @@
# Parsec Cloud (https://parsec.cloud) Copyright (c) AGPLv3 2019 Scille SAS

import pytest
import os
import re
import pytest
import psutil
import pathlib
import subprocess

from parsec.core.config import config_factory
from parsec.core.local_device import list_available_devices


def kill_local_backend(backend_port=6888):
pattern = f"parsec.* backend.* run.* -P {backend_port}"
for proc in psutil.process_iter():
if "python" in proc.name():
arguments = " ".join(proc.cmdline())
if re.search(pattern, arguments):
proc.kill()


@pytest.fixture
def run_testenv():
try:
# Source the run_testenv script and echo the testenv path
os.chdir(os.path.dirname(__file__))
if os.name == "nt":
output = subprocess.check_output(
"scripts\\run_testenv.bat && echo %APPDATA%", shell=True
)
else:
output = subprocess.check_output(
"source scripts/run_testenv.sh && echo $XDG_CONFIG_HOME",
shell=True,
executable="bash",
)

# Retrieve the testenv path
testenv_path = pathlib.Path(output.splitlines()[-1].decode())
if os.name == "nt":
data_path = testenv_path / "parsec" / "data"
cache_path = testenv_path / "parsec" / "cache"
config_path = testenv_path / "parsec" / "config"
else:
testenv_path = testenv_path.parent
data_path = testenv_path / "share" / "parsec"
cache_path = testenv_path / "cache" / "parsec"
config_path = testenv_path / "config" / "parsec"

# Make sure the corresponding directories exist
assert testenv_path.exists()
assert data_path.exists()
assert cache_path.exists()
assert config_path.exists()

# Return a core configuration
yield config_factory(
config_dir=config_path, data_base_dir=data_path, cache_base_dir=cache_path
)

@pytest.mark.skipif(os.name != "posix", reason="Test for linux")
def test_run_test_env_linux():
os.chdir(os.path.dirname(__file__))
assert os.system('bash -c "source scripts/run_testenv.sh"') == 0
# Make sure we don't leave a backend running as it messes up with the CI
finally:
kill_local_backend()


@pytest.mark.skipif(os.name != "nt", reason="Test for windows")
def test_run_test_env_windows():
os.chdir(os.path.dirname(__file__))
assert os.system("scripts\\run_testenv.bat") == 0
@pytest.mark.slow
@pytest.mark.skipif(os.name == "nt", reason="causes a freeze in appveyor for some reasons")
def test_run_testenv(run_testenv):
devices = list_available_devices(run_testenv.config_dir)
_, devices, _, _ = zip(*devices)
assert sorted(devices) == ["alice@laptop", "alice@pc", "bob@laptop"]

0 comments on commit fcfd802

Please sign in to comment.