Skip to content

Commit

Permalink
Viashpy 0.6.0 (#20)
Browse files Browse the repository at this point in the history
* CI: Use viash-actions/setup for installing viash

* Remove bin folder

* Fix bugs and update CI

* Python 3.12

* Propagate is True by default

* Undo logging statement change

* Add CHANGELOG entries and fix logging

* Add CHANGELOG entry

* Enabling different pytest versions in CI

* tox's --skip-env accepts regex matching

* Remove dots from python versions in matrix

* Does this substitution work?

* Remove quotes

* Fix regex

* Pytester was only added in pytest 6.2

* Dot not install pytest twice

* Try removing deprecationwarnings

* Fix formatting

* Fix tests for python 3.12

* Take extra warnings into account

* Simplify memory specification

* Fix formatting
  • Loading branch information
DriesSchaumont authored Jan 22, 2024
1 parent 97d6aa7 commit ad2d20a
Show file tree
Hide file tree
Showing 13 changed files with 227 additions and 105 deletions.
15 changes: 7 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
Expand All @@ -36,16 +36,15 @@ jobs:
- name: Install tox
run: python -m pip install tox
- name: Test
run: tox -e py${{ matrix.python-version }}
run: |
PYTHON_ENV="${{ matrix.python-version }}"
PYTHON_ENV_NO_DOTS=${PYTHON_ENV//.}
tox run --skip-env '^(?!py'$PYTHON_ENV_NO_DOTS').+'
integration_tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Fetch viash
run: |
bin/init -n
tree .
bin/viash -h
- uses: viash-io/viash-actions/setup@v4
- name: Viash ns test
run: |
./bin/viash ns test -s tests/integration/ -p docker --memory 1GB
viash ns test -s tests/integration/ -p docker --memory 1GB
19 changes: 19 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@
Changelog
*********

0.6.0 (TBD)
===========

Breaking Changes
----------------
* The minimum supported version of pytest is now `6.2` (PR #20).

Minor Changes
-------------
* Added support for python 3.12 (PR #20).
* (development) Removed the bin/ folder in favour of a viash project config (`_viash.yaml`) (PR #20).

Bug fixes
---------
* Fix `run_component` setting `--memory` and `--cpu` at the incorrect location in the `viash run` command (PR #20).
* Fix tests for pytest versions older than `7.0` (PR #20).
* Match the logging level to the level in the config from pytest (see pytests' `--log-cli-level`) (PR #20)


0.5.0 (6/10/2023)
================

Expand Down
1 change: 1 addition & 0 deletions _viash.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
viash_version: 0.8.2
51 changes: 0 additions & 51 deletions bin/init

This file was deleted.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = 'setuptools.build_meta'
write_to = "viashpy/__version__.py"

[tool.black]
target-version = ['py39', 'py310', 'py311']
target-version = ['py39', 'py310', 'py311', 'py312']
exclude = '''
(
\.egg
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ setup_requires =
setuptools-scm
setuptools_scm_git_archive
install_requires =
pytest >= 3.5
pytest >= 6.2
PyYAML ~= 6.0

[options.extras_require]
Expand Down
20 changes: 20 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
from _pytest.logging import get_log_level_for_setting
import logging

pytest_plugins = "pytester"


def pytest_configure(config):
# Some of the pytest functions used here are not officially exposed through
# their API. We test for different pytest versions so should be OK.
level = get_log_level_for_setting(config, "log_cli_level")
if not level:
level = logging.WARNING
handler = logging.StreamHandler()
handler.setLevel(level)
# Set levels on the root logger. Logging events are passed up
# the chain to the root logger, which will emit the events.
# For this to happen, the non-root loggers need to have set 'propagate'
# to 'True', which is the default.
root_logger = logging.getLogger()
root_logger.setLevel(level)
root_logger.addHandler(handler)
10 changes: 9 additions & 1 deletion tests/integration/test_run_component/dummy_config.vsh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ functionality:
test_resources:
- type: python_script
path: test_script.py
- path: /tests/integration/test_run_component/dummy_config.vsh.yaml
platforms:
- type: native
- type: docker
image: python:3.10
test_setup:
Expand All @@ -32,5 +34,11 @@ platforms:
- type: python
packages:
- /viashpy
- type: native
- ruamel.yaml
- type: apt
packages:
- default-jdk
- type: docker
run: |
curl -fsSL dl.viash.io | bash; mv viash /usr/local/bin/
- type: nextflow
89 changes: 73 additions & 16 deletions tests/integration/test_run_component/test_script.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import pytest
import sys
from pathlib import Path
from io import StringIO
from contextlib import redirect_stdout
from ruamel.yaml import YAML
from contextlib import redirect_stdout, redirect_stderr
import uuid

### VIASH START # noqa: E266
meta = {
Expand All @@ -10,29 +13,83 @@
### VIASH END # noqa: E266


def test_run_component(run_component):
captured_output = run_component(["--output", "bar.txt"])
with open("bar.txt", "r") as open_output_file:
contents = open_output_file.read()
assert contents == "foo!"
assert (
captured_output is not None
), "Some output from stdout or stderr should have been captured"
assert b"This is a logging statement" in captured_output
@pytest.fixture()
def random_config_path(tmp_path):
def wrapper():
unique_filename = f"{str(uuid.uuid4())}.vsh.yaml"
temp_file = tmp_path / unique_filename
return temp_file

return wrapper

if __name__ == "__main__":

class TestRunExecutable:
meta = meta

def test_run_component(self, run_component):
captured_output = run_component(["--output", "bar.txt"])
with open("bar.txt", "r") as open_output_file:
contents = open_output_file.read()
assert contents == "foo!"
assert (
captured_output is not None
), "Some output from stdout or stderr should have been captured"
assert b"This is a logging statement" in captured_output


class TestRunUsingConfig:
meta = meta

@pytest.fixture()
def viash_source_config_path(self, random_config_path):
yaml_interface = YAML(typ="safe", pure=True)
yaml_interface.default_flow_style = False
original_config = yaml_interface.load(
Path(f"{meta['resources_dir']}/dummy_config.vsh.yaml")
)
del original_config["functionality"]["test_resources"]
del original_config["functionality"]["resources"][1]
result_path = random_config_path()
yaml_interface.dump(original_config, result_path)
return result_path

def test_run_component_check_correct_memory_syntax(self, run_component):
captured_output = run_component(["--output", "bar.txt"])
with open("bar.txt", "r") as open_output_file:
contents = open_output_file.read()
assert contents == "foo!"
assert (
captured_output is not None
), "Some output from stdout or stderr should have been captured"
assert (
b"--memory looks like a parameter but is not a defined parameter and will instead be treated as a positional argument"
not in captured_output
)


def run_pytest_and_capture_output():
temp_stdout = StringIO()
temp_stderr = StringIO()
print(f"meta: {meta}")
with redirect_stdout(temp_stdout), redirect_stderr(temp_stderr):
exit_code = pytest.main(
[__file__, "--log-cli-level", "DEBUG"], plugins=["viashpy"]
)
stdout_str = temp_stdout.getvalue()
stderr_str = temp_stderr.getvalue()
print(f"stdout: {stdout_str}\nstderr: {stderr_str}\nexit_code: {exit_code}")
return stdout_str, stderr_str, exit_code


if __name__ == "__main__":
assert (
meta["memory_gb"] is not None
), "This test should be executed with some --memory set."
with redirect_stdout(temp_stdout):
result = pytest.main([__file__], plugins=["viashpy"])
stdout_str = temp_stdout.getvalue()
print(stdout_str)

stdout_str, stderr_str, exit_code = run_pytest_and_capture_output()
assert (
"Different values were defined in the 'meta' dictionary that limit memory, choosing the one with the smallest unit"
not in stdout_str
)
sys.exit(result)

sys.exit(exit_code)
Loading

0 comments on commit ad2d20a

Please sign in to comment.