matrix tests: Refactor running script into helper function.
This commit is contained in:
parent
fd66eb61c7
commit
c692c4712a
|
@ -6,12 +6,18 @@ script_file = "matrix_bridge.py"
|
||||||
script_dir = os.path.dirname(__file__)
|
script_dir = os.path.dirname(__file__)
|
||||||
script = os.path.join(script_dir, script_file)
|
script = os.path.join(script_dir, script_file)
|
||||||
|
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
|
||||||
class MatrixBridgeTests(TestCase):
|
class MatrixBridgeTests(TestCase):
|
||||||
|
def output_from_script(self, options):
|
||||||
|
# type: (List[str]) -> List[str]
|
||||||
|
popen = Popen(["python", script] + options, stdin=PIPE, stdout=PIPE, universal_newlines=True)
|
||||||
|
return popen.communicate()[0].strip().split("\n")
|
||||||
|
|
||||||
def test_no_args(self):
|
def test_no_args(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
popen = Popen(["python", script], stdin=PIPE, stdout=PIPE, universal_newlines=True)
|
output_lines = self.output_from_script([])
|
||||||
output_lines = popen.communicate()[0].strip().split("\n")
|
|
||||||
expected_lines = [
|
expected_lines = [
|
||||||
"Options required: -c or --config to run, OR --write-sample-config.",
|
"Options required: -c or --config to run, OR --write-sample-config.",
|
||||||
"usage: {} [-h]".format(script_file)
|
"usage: {} [-h]".format(script_file)
|
||||||
|
@ -21,8 +27,7 @@ class MatrixBridgeTests(TestCase):
|
||||||
|
|
||||||
def test_help_usage_and_description(self):
|
def test_help_usage_and_description(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
popen = Popen(["python", script] + ["-h"], stdin=PIPE, stdout=PIPE, universal_newlines=True)
|
output_lines = self.output_from_script(["-h"])
|
||||||
output_lines = popen.communicate()[0].strip().split("\n")
|
|
||||||
usage = "usage: {} [-h]".format(script_file)
|
usage = "usage: {} [-h]".format(script_file)
|
||||||
description = "Script to bridge"
|
description = "Script to bridge"
|
||||||
self.assertIn(usage, output_lines[0])
|
self.assertIn(usage, output_lines[0])
|
||||||
|
|
Loading…
Reference in a new issue