Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests #71

Merged
merged 6 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dockerc
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ elif [ "$(echo "$ARGS" | cut -c1)" = '@' ]; then
echo ' @b build'
echo ' @bp build --pull'
echo ' @bf build --pull --no-cache'
echo ' @bn build --dry-run --pull --no-cache'
echo ' @bn build --dry-run --pull --no-cache'
echo ' @d down'
echo ' @da down --remove-orphans'
echo ' @dr down --remove-orphans --rmi local'
Expand Down Expand Up @@ -764,7 +764,7 @@ elif [ "$(echo "$ARGS" | cut -c1)" = '@' ]; then
echo " @llts logs -t --no-log-prefix"
echo ' @p ps'
echo ' @pa ps -a'
echo ' @pu push'
echo ' @pu push'
echo ' @pl pull'
echo ' @rs rm --stop'
echo ' @rf rm -f'
Expand Down
38 changes: 31 additions & 7 deletions test/src/RunDockerc.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
import subprocess

class RunDockerc():
Expand Down Expand Up @@ -27,26 +28,49 @@ def __init__(

def assert_context(
self,
stdout: bytes | None = None,
stderr: bytes | None = None,
stdout: bytes | re.Pattern | None = None,
stderr: bytes | re.Pattern | None = None,
returncode: int = 0,
):
assert self.proc_stdout == stdout
assert self.proc_stderr == stderr
# if self.proc_stdout != stdout:
# # Debugging
# import difflib
# diff = difflib.unified_diff(
# self.proc_stdout.decode('utf-8').splitlines(keepends = True),
# (
# stdout.decode('utf-8').splitlines(keepends = True)
# if isinstance(stdout, bytes) else
# stdout.pattern.splitlines(keepends = True)
# if isinstance(stdout, re.Pattern) else
# stdout
# ),
# )
# print(''.join(diff))

if isinstance(stdout, re.Pattern):
assert stdout.match(self.proc_stdout.decode('utf-8'))
else:
assert self.proc_stdout == stdout

if isinstance(stderr, re.Pattern):
assert stderr.match(self.proc_stderr.decode('utf-8'))
else:
assert self.proc_stderr == stderr

assert self.proc.returncode == returncode

def assert_context_found(
self,
stdout: bytes = b'',
stdout: bytes | re.Pattern = b'',
):
return self.assert_context(
stdout = stdout,
)

def assert_context_error(
self,
stdout: bytes | None = None,
stderr: bytes | None = None,
stdout: bytes | re.Pattern | None = None,
stderr: bytes | re.Pattern | None = None,
):
return self.assert_context(
**({'stdout': stdout} if stdout is not None else {}),
Expand Down
22 changes: 16 additions & 6 deletions test/test/help/test_version.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
import re

from test.src.TestDirContext import TestDirContext

VERSION_STDOUT_SHORT = (
b'DockerC (v1.8.2) - https://github.com/matiboux/dockerc\n'
VERSION_STDOUT_SHORT_REGEX = (
'^DockerC \(v[0-9]+\.[0-9]+\.[0-9]+\) - https://github\.com/matiboux/dockerc\n$'
)

def test_version(file = __file__):
with TestDirContext(file) as ctx:
dockerc = ctx.run_dockerc(
'--version',
)
dockerc.assert_context_found(VERSION_STDOUT_SHORT)
dockerc.assert_context_found(
re.compile(VERSION_STDOUT_SHORT_REGEX)
)

def test_version_shorthand(file = __file__):
with TestDirContext(file) as ctx:
dockerc = ctx.run_dockerc(
'-v',
)
dockerc.assert_context_found(VERSION_STDOUT_SHORT)
dockerc.assert_context_found(
re.compile(VERSION_STDOUT_SHORT_REGEX)
)

def test_version_dry(file = __file__):
with TestDirContext(file) as ctx:
dockerc = ctx.run_dockerc(
'-n', '--version',
)
dockerc.assert_context_found(VERSION_STDOUT_SHORT)
dockerc.assert_context_found(
re.compile(VERSION_STDOUT_SHORT_REGEX)
)

def test_version_dry_shorthand(file = __file__):
with TestDirContext(file) as ctx:
dockerc = ctx.run_dockerc(
'-n', '-v',
)
dockerc.assert_context_found(VERSION_STDOUT_SHORT)
dockerc.assert_context_found(
re.compile(VERSION_STDOUT_SHORT_REGEX)
)