Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #75 from riotkit-org/issue_74
Browse files Browse the repository at this point in the history
#74: Migrate to PyTest
  • Loading branch information
blackandred committed Jun 12, 2021
2 parents 58eba50 + 47a6150 commit 3fedfc7
Show file tree
Hide file tree
Showing 17 changed files with 325 additions and 36 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/test-and-release-rkd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ jobs:
- name: Run RKD tests on Python ${{ matrix.python-version }}
run: "make tests"

- name: Archive RKD tests results
uses: dorny/test-reporter@v1
if: always()
with:
name: "[${{ matrix.python-version }}] RKD tests"
path: build/tests.xml
reporter: java-junit

- name: Run rkd_python tests on Python ${{ matrix.python-version }}
run: "cd subpackages/rkd_python && make tests"

Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ TEST_OPTS=

## Run tests
tests: refresh_git
export PYTHONPATH="$$(pwd):$$(pwd)/subpackages/rkd_python"; \
python3 -m unittest discover -s ./test ${TEST_OPTS}
RKD_BIN="python -m rkd" PYTHONPATH="$$(pwd):$$(pwd)/subpackages/rkd_python" pytest ./test --junitxml=build/tests.xml

## Release
release: package publish
Expand Down
17 changes: 17 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
jsonschema = ">=3.2.0"
pbr = ">=5.4.5"
python-dotenv = "==0.13.0"
tabulate = "==0.8.7"
Jinja2 = ">=2.11"
PyYAML = ">=5.3.1"

[dev-packages]
pytest = "*"
psutil = "*"

255 changes: 255 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pipenv>=2018.11.26
psutil==5.7.2
pytest==6.2.*
11 changes: 9 additions & 2 deletions rkd/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
making it impossible to capture the text for logging.
"""

import io
import os
import sys
import subprocess
Expand Down Expand Up @@ -109,6 +109,13 @@ def check_call(command: str, script_to_show: Optional[str] = '',
old_tty = termios.tcgetattr(sys.stdin)
except termios.error:
old_tty = None
except io.UnsupportedOperation:
old_tty = None

try:
sys.stdin.fileno()
except io.UnsupportedOperation:
old_tty = None

# merge system environment with environment from parameters
if env:
Expand Down Expand Up @@ -238,7 +245,7 @@ def push_output(process, primary_fd, out_buffer: TextBuffer, process_state: Proc
while process.poll() is None:
for r, flags in poller.poll(timeout=0.01):
try:
if sys.stdin.fileno() is r:
if is_interactive_session and sys.stdin.fileno() is r:
d = os.read(r, 10240)
os.write(primary_fd, d)

Expand Down
4 changes: 2 additions & 2 deletions rkd/standardlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
from ..api.syntax import TaskDeclaration
from ..inputoutput import clear_formatting
from ..aliasgroups import parse_alias_groups_from_env, AliasGroup
from .shell import ShellCommandTask
from ..packaging import find_resource_directory
from rkd import env
from .. import env
from .shell import ShellCommandTask


class InitTask(TaskInterface):
Expand Down
2 changes: 1 addition & 1 deletion rkd/taskutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get_rkd_binary():
binary = sys.argv[0]
sys_executable_basename = os.path.basename(sys.executable)

if "-m unittest" in binary:
if "-m unittest" in binary or "pytest" in binary:
return binary.split(' ')[0] + ' -m rkd'

# as a Python module: "python -m rkd" for example
Expand Down
7 changes: 4 additions & 3 deletions rkd/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
from .api.inputoutput import NullSystemIO


class TestTask(CallableTask):
class TaskForTesting(CallableTask):
_description = 'Test task for automated tests'
_become: str = False

def __init__(self):
self._io = NullSystemIO()
super().__init__(':test', None)

def get_name(self) -> str:
return ':test'
Expand All @@ -42,15 +43,15 @@ def get_declared_envs(self) -> Dict[str, str]:
}


class TestTaskWithRKDCallInside(TestTask):
class TaskForTestingWithRKDCallInside(TaskForTesting):
def execute(self, context: ExecutionContext) -> bool:
self.rkd([':sh', '-c', '"echo \'9 Aug 2014 Michael Brown, an unarmed Black teenager, was killed by a white police officer in Ferguson, Missouri, sparking mass protests across the US.\'"'])
return True


def get_test_declaration(task: TaskInterface = None) -> TaskDeclaration:
if not task:
task = TestTask()
task = TaskForTesting()

return TaskDeclaration(task, {}, [])

Expand Down

0 comments on commit 3fedfc7

Please sign in to comment.