Skip to content

Commit

Permalink
run: Normalize paths
Browse files Browse the repository at this point in the history
Fixes #364.

Signed-off-by: Stephen Finucane <[email protected]>
  • Loading branch information
stephenfin committed Aug 29, 2024
1 parent 279b18b commit 4328e81
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions stestr/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ def run_command(
ids, klass = ids.split("::", 1)
klass = ".".join(klass.split("::"))
if ids.find(os.path.sep) != -1:
root, _ = os.path.splitext(ids)
root, _ = os.path.splitext(os.path.normpath(ids))
ids = ".".join(root.split(os.path.sep))
if klass:
ids = f"{ids}.{klass}"
Expand Down Expand Up @@ -594,7 +594,7 @@ def run_tests():
ids, klass = ids.split("::", 1)
klass = ".".join(klass.split("::"))
if ids.find(os.path.sep) != -1:
root, _ = os.path.splitext(ids)
root, _ = os.path.splitext(os.path.normpath(ids))
ids = ".".join(root.split(os.path.sep))
if klass:
ids = f"{ids}.{klass}"
Expand Down
18 changes: 18 additions & 0 deletions stestr/tests/test_return_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,24 @@ def test_run_no_discover_file_path_failing(self):
self.assertIn(" - Failed: 2", lines)
self.assertIn(" - Unexpected Success: 1", lines)

def test_run_no_discover_unnormalized_file_path(self):
# we don't use os.path.join since we want an unnormalized path
passing_string = f"tests{os.path.sep}{os.path.sep}test_passing.py"
out, err = self.assertRunExit("stestr run -n %s" % passing_string, 0)
lines = out.decode("utf8").splitlines()
self.assertIn(" - Passed: 2", lines)
self.assertIn(" - Failed: 0", lines)
self.assertIn(" - Expected Fail: 1", lines)

def test_run_no_discover_unnormalized_file_path_failing(self):
# we don't use os.path.join since we want an unnormalized path
failing_string = f"tests{os.path.sep}{os.path.sep}test_failing.py"
out, err = self.assertRunExit("stestr run -n %s" % failing_string, 1)
lines = out.decode("utf8").splitlines()
self.assertIn(" - Passed: 0", lines)
self.assertIn(" - Failed: 2", lines)
self.assertIn(" - Unexpected Success: 1", lines)


class TestReturnCodesToxIni(TestReturnCodes):
def setUp(self):
Expand Down

0 comments on commit 4328e81

Please sign in to comment.