Skip to content

Commit

Permalink
Making lint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
kohsuke committed Jul 28, 2023
1 parent 95be615 commit f99e6ac
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
46 changes: 24 additions & 22 deletions launchable/test_runners/nunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,25 @@
# nested <test-suite>s

"""
Nested class name handling in .NET
---------------------------------
Nested class 'Zot' in the following example gets the full name "Foo.Bar+Zot":
namespace Foo {
class Bar {
class Zot {
}}}
This is incontrast to how you refer to this class from the source code. For example,
"new Foo.Bar.Zot()"
The subset command expects the list of tests to be passed to "nunit --testlist" option,
and this option expects test names to be in "Foo.Bar+Zot" format.
Nested class name handling in .NET
---------------------------------
Nested class 'Zot' in the following example gets the full name "Foo.Bar+Zot":
namespace Foo {
class Bar {
class Zot {
}}}
This is incontrast to how you refer to this class from the source code. For example,
"new Foo.Bar.Zot()"
The subset command expects the list of tests to be passed to "nunit --testlist" option,
and this option expects test names to be in "Foo.Bar+Zot" format.
"""


def build_path(e: Element):
pp = [] # type: TestPath
if e.parent:
Expand All @@ -47,21 +48,22 @@ def build_path(e: Element):
if idx >= 0:
# when things are going well, method name cannot contain '.' since it's not a valid character in a symbol.
# but when NUnitXML.Logger messes up, it ends up putting the class name and the method name, like
# <test-case name="TheTest" fullname="Launchable.NUnit.Test.Outer+Inner.TheTest" methodname="Outer+Inner.TheTest" classname="Test"
# <test-case name="TheTest" fullname="Launchable.NUnit.Test.Outer+Inner.TheTest"
# methodname="Outer+Inner.TheTest" classname="Test"

pp = pp[0:-1] + [
# NUnitXML.Logger mistreats the last portion of the namespace as a test fixture when it really should be test suite
# So we patch that up too. This is going beyond what's minimally required to make subset work, because type information
# won't impact how the test path is printed, but when NUnitXML.Logger eventually fixes this bug, we don't want that
# to produce different test paths.
# NUnitXML.Logger mistreats the last portion of the namespace as a test fixture when
# it really should be test suite. So we patch that up too. This is going beyond what's minimally required
# to make subset work, because type information won't impact how the test path is printed, but
# when NUnitXML.Logger eventually fixes this bug, we don't want that to produce different test paths.
{'type': 'TestSuite', 'name': pp[-1]['name']},
# Here, we need to insert the missing TestFixture=Outer+Inner.
# I chose TestFixture because that's what nunit console runner (which we believe is handling it correctly)
# chooses as its type.
{'type': 'TestFixture', 'name': methodname[0:idx]}
]

pp = pp + [{'type': 'TestCase', 'name': e.attrs['name'] }]
pp = pp + [{'type': 'TestCase', 'name': e.attrs['name']}]

if len(pp) > 0:
def split_filepath(path: str) -> List[str]:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_runners/test_nunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ def test_record_test_with_nunit_reporter_bug(self):

payload = json.loads(gzip.decompress(responses.calls[1].request.body).decode())

# turns out we collapse all TestFixtures to TestSuitest so the golden file has TestSuite=Outer+Inner, not TestFixture=Outer+Inner
# turns out we collapse all TestFixtures to TestSuitest so the golden file has TestSuite=Outer+Inner,
# not TestFixture=Outer+Inner
expected = self.load_json_from_file(self.test_files_dir.joinpath("nunit-reporter-bug-with-nested-type.json"))

self.assert_json_orderless_equal(expected, payload)

0 comments on commit f99e6ac

Please sign in to comment.