-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #161 from launchableinc/ST-821-behave-runner
[ST-821] support behave runner
- Loading branch information
Showing
5 changed files
with
120 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import click | ||
from . import launchable | ||
from xml.etree import ElementTree as ET | ||
import os | ||
|
||
|
||
@click.argument('reports', required=True, nargs=-1) | ||
@launchable.record.tests | ||
def record_tests(client, reports): | ||
for r in reports: | ||
client.report(r) | ||
|
||
def parse_func(p: str) -> ET.ElementTree: | ||
tree = ET.parse(p) | ||
for suite in tree.iter("testsuite"): | ||
if len(suite) == 0: | ||
continue | ||
|
||
name = suite.get('name') | ||
if name is None: | ||
continue | ||
|
||
suite_name = name.split('.') | ||
if len(suite_name) < 2: | ||
continue | ||
|
||
file_name = suite_name[0] + ".feature" | ||
class_name = suite_name[1] | ||
suite.attrib.update({"filepath": file_name}) | ||
|
||
for case in suite: | ||
case.attrib.update({"classname": class_name}) | ||
|
||
return tree | ||
|
||
client._junitxml_parse_func = parse_func | ||
client.run() | ||
|
||
|
||
@launchable.subset | ||
def subset(client): | ||
for t in client.stdin(): | ||
if 0 < t.find(".feature"): | ||
paths = os.path.split(t) | ||
if len(paths) < 2: | ||
continue | ||
|
||
file = paths[1] | ||
client.test_path(file.rstrip('\n')) | ||
|
||
client.separator = "|" | ||
client.run() |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{"events": [ | ||
{"type": "case", "testPath": [{"type": "file", "name": "tutorial.feature"}, {"type": "class", "name": "showing off behave"}, {"type": "testcase", "name": "run a simple test", "_lineno": null}], "duration": 0.000202, "status": 1, "stdout": "", "stderr": "", "data": null} | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<testsuite name="tutorial.showing off behave" tests="1" errors="0" failures="0" skipped="0" time="0.000202" timestamp="2021-03-04T16:03:07.132143" hostname="localhost"><testcase classname="tutorial.showing off behave" name="run a simple test" status="passed" time="0.000202"><system-out> | ||
<![CDATA[ | ||
@scenario.begin | ||
Scenario: run a simple test | ||
Given we have behave installed ... passed in 0.000s | ||
When we implement a test ... passed in 0.000s | ||
Then behave will test it for us! ... passed in 0.000s | ||
@scenario.end | ||
-------------------------------------------------------------------------------- | ||
]]> | ||
</system-out></testcase></testsuite> |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"testPaths": [ | ||
[{"type": "file", "name": "tutorial.feature"}] | ||
], | ||
"target": 0.1, | ||
"session": { | ||
"id": "16" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from pathlib import Path | ||
from unittest import mock | ||
import responses # type: ignore | ||
import json | ||
import gzip | ||
from tests.cli_test_case import CliTestCase | ||
|
||
|
||
class BehaveTest(CliTestCase): | ||
test_files_dir = Path(__file__).parent.joinpath( | ||
'../data/behave/').resolve() | ||
|
||
@responses.activate | ||
def test_subset(self): | ||
pipe = "tutorial.feature" | ||
result = self.cli('subset', '--target', '10%', '--session', | ||
self.session, 'behave', input=pipe) | ||
self.assertEqual(result.exit_code, 0) | ||
|
||
payload = json.loads(gzip.decompress( | ||
responses.calls[0].request.body).decode()) | ||
|
||
expected = self.load_json_from_file( | ||
self.test_files_dir.joinpath('subset_result.json')) | ||
|
||
self.assert_json_orderless_equal(expected, payload) | ||
|
||
@ responses.activate | ||
def test_record_test_maven(self): | ||
result = self.cli('record', 'tests', '--session', self.session, | ||
'behave', str(self.test_files_dir) + "/reports/report.xml") | ||
self.assertEqual(result.exit_code, 0) | ||
|
||
payload = json.loads(gzip.decompress( | ||
b''.join(responses.calls[0].request.body)).decode()) | ||
|
||
for e in payload["events"]: | ||
del e["created_at"] | ||
|
||
expected = self.load_json_from_file( | ||
self.test_files_dir.joinpath("record_test_result.json")) | ||
|
||
self.assert_json_orderless_equal(expected, payload) |