-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add type-annotations - Blacken code (100-character line-length) - Reformat docstrings to PEP257.
- Loading branch information
Showing
28 changed files
with
1,155 additions
and
946 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,12 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# environment.py | ||
# | ||
# Copyright (C) 2013 Steve Canny [email protected] | ||
# | ||
# This module is part of python-opc and is released under the MIT License: | ||
# http://www.opensource.org/licenses/mit-license.php | ||
|
||
""" | ||
Used by behave to set testing environment before and after running acceptance | ||
tests. | ||
""" | ||
"""Used by behave to set testing environment before and after running acceptance tests.""" | ||
|
||
import os | ||
|
||
from behave.runner import Context | ||
|
||
scratch_dir = os.path.abspath(os.path.join(os.path.split(__file__)[0], "_scratch")) | ||
|
||
|
||
def before_all(context): | ||
def before_all(context: Context): | ||
if not os.path.isdir(scratch_dir): | ||
os.mkdir(scratch_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,25 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# helpers.py | ||
# | ||
# Copyright (C) 2012, 2013 Steve Canny [email protected] | ||
# | ||
# This module is part of opc-diag and is released under the MIT License: | ||
# http://www.opensource.org/licenses/mit-license.php | ||
|
||
"""Acceptance test helpers.""" | ||
|
||
from __future__ import unicode_literals | ||
# pyright: reportPrivateUsage=false | ||
|
||
from __future__ import annotations | ||
|
||
import os | ||
import subprocess | ||
|
||
from step_data import Manifest | ||
from step_data import Manifest, _Manifest | ||
|
||
|
||
def absjoin(*paths): | ||
def absjoin(*paths: str): | ||
return os.path.abspath(os.path.join(*paths)) | ||
|
||
|
||
def ref_pkg_path(filename): | ||
def ref_pkg_path(filename: str): | ||
ref_pkg_dir = absjoin(test_file_dir, "reference_pkgs") | ||
return os.path.relpath(absjoin(ref_pkg_dir, filename)) | ||
|
||
|
||
def scratch_path(name): | ||
def scratch_path(name: str): | ||
return os.path.relpath(absjoin(scratch_dir, name)) | ||
|
||
|
||
|
@@ -35,35 +28,29 @@ def scratch_path(name): | |
test_file_dir = absjoin(thisdir, "../test_files") | ||
|
||
|
||
def assertManifestsMatch(manifest1, manifest2, name1, name2): | ||
""" | ||
Raise |AssertionError| if *manifest1* does not exactly match *manifest2*. | ||
*name1* and *name2* appear in the diff printed if the assertion fails. | ||
def assertManifestsMatch(manifest1: _Manifest, manifest2: _Manifest, name1: str, name2: str): | ||
"""Raise |AssertionError| if `manifest1` does not exactly match `manifest2`. | ||
`name1` and `name2` appear in the diff printed if the assertion fails. | ||
""" | ||
msg = "Package manifests don't match\n\n%s" % manifest1.diff( | ||
manifest2, name1, name2 | ||
) | ||
msg = "Package manifests don't match\n\n%s" % manifest1.diff(manifest2, name1, name2) | ||
assert manifest1 == manifest2, msg | ||
|
||
|
||
def assertPackagesMatch(path1, path2): | ||
""" | ||
Raise |AssertionError| if manifest of package at *path1* does not exactly | ||
match that of package at *path2*. | ||
def assertPackagesMatch(path1: str, path2: str): | ||
"""Raise if manifest of package at `path1` does not exactly match that of package at `path2`. | ||
Raises `AssertionError` in that case. | ||
""" | ||
manifest1, manifest2 = Manifest(path1), Manifest(path2) | ||
msg = "Package manifests don't match\n\n%s" % manifest1.diff( | ||
manifest2, path1, path2 | ||
) | ||
msg = "Package manifests don't match\n\n%s" % manifest1.diff(manifest2, path1, path2) | ||
assert manifest1 == manifest2, msg | ||
|
||
|
||
class OpcCommand(object): | ||
""" | ||
Executes opc-diag command as configured and makes results available. | ||
""" | ||
class OpcCommand: | ||
"""Executes opc-diag command as configured and makes results available.""" | ||
|
||
def __init__(self, subcommand, *args): | ||
def __init__(self, subcommand: str, *args: str): | ||
self.subcommand = subcommand | ||
self.args = args | ||
|
||
|
@@ -83,11 +70,11 @@ def assert_stdout_empty(self): | |
tmpl = "Unexpected output on stdout\n'%s'\n" | ||
assert self.std_out == "", tmpl % self.std_out | ||
|
||
def assert_stdout_matches(self, filename): | ||
""" | ||
Raise AssertionError with helpful diagnostic message if output | ||
captured on stdout doesn't match contents of file identified by | ||
*filename* in known directory. | ||
def assert_stdout_matches(self, filename: str): | ||
"""Raise if captured stdout does not match contents of `filename`. | ||
Raise AssertionError with helpful diagnostic message if output captured on stdout doesn't | ||
match contents of file identified by `filename` in known directory. | ||
""" | ||
expected_stdout = self._expected_output(filename) | ||
msg = "\n\nexpected output:\n'%s'\n\nactual output:\n'%s'" % ( | ||
|
@@ -98,26 +85,19 @@ def assert_stdout_matches(self, filename): | |
assert std_out == expected_stdout, msg | ||
|
||
def execute(self): | ||
""" | ||
Execute the configured command in a subprocess and capture the | ||
results. | ||
""" | ||
"""Execute the configured command in a subprocess and capture the results.""" | ||
args = ["python", "opc-stub"] | ||
args.append(self.subcommand) | ||
args.extend(self.args) | ||
self.proc = subprocess.Popen( | ||
args, stdout=subprocess.PIPE, stderr=subprocess.PIPE | ||
) | ||
self.proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
std_out_bytes, std_err_bytes = self.proc.communicate() | ||
self.std_out = std_out_bytes.decode("utf-8") | ||
self.std_err = std_err_bytes.decode("utf-8") | ||
return self | ||
|
||
@staticmethod | ||
def _expected_output(filename): | ||
""" | ||
Return contents of file with *filename* in known directory as text. | ||
""" | ||
def _expected_output(filename: str): | ||
"""Return contents of file with `filename` in known directory as text.""" | ||
path = absjoin(test_file_dir, "expected_output", filename) | ||
with open(path, "rb") as f: | ||
expected_bytes = f.read() | ||
|
Oops, something went wrong.