Skip to content

Commit 3a82ecd

Browse files
committed
Fix compute_relative_path coverage gap and note observer.py recursion bugs
The previous compute_relative_path test passed None for ``path`` but posixpath.relpath silently substitutes ``os.curdir`` for a None start, so the success branch ran and lines 149-150 (the except + fallback) stayed uncovered. Switching to a non-path-like ``file`` argument forces os.fspath to raise TypeError inside os.path.relpath, which is what the except clause was written to handle. Adds a comment at the top of observer_pyt.py explaining why the self-recursive method bodies in observer.py are deliberately not covered -- they would recurse until the stack overflows. The recursion appears to be a production-code bug; a follow-up commit (outside this test-only branch) should replace ``self.X(...)`` with ``super().X(...)`` or remove the bodies entirely.
1 parent 057d912 commit 3a82ecd

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

_package/tests/unit_tests/filesystem_pyt.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,8 @@ def test_does_file_exist_swallows_errors(self):
367367

368368
def test_compute_relative_path_swallows_errors(self):
369369
"""compute_relative_path falls back to str(file) when relpath raises."""
370-
# None breaks os.path.relpath with TypeError, exercising the except branch.
371-
# The fallback returns str(file) with backslashes flipped to forward slashes.
372-
result = compute_relative_path(None, 'D:\\some\\path')
373-
self.assertEqual('D:/some/path', result)
370+
# Passing a non-path-like 'file' argument forces os.path.relpath to raise
371+
# (it calls os.fspath on it), exercising the except branch. The fallback
372+
# is ``str(file).replace('\\', '/')`` -- here ``str(12345)`` -> ``'12345'``.
373+
result = compute_relative_path('/some/base', 12345)
374+
self.assertEqual('12345', result)

_package/tests/unit_tests/observer_pyt.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
"""
22
Test InterpLinear_py.cpp.
33
"""
4+
# NOTE on the deliberately-uncovered lines in xms/core/misc/observer.py:
5+
#
6+
# Observer.on_progress_status, on_begin_operation_string, on_end_operation,
7+
# on_update_message, time_remaining_in_seconds, and time_elapsed_in_seconds
8+
# each have a single-line body that calls the *same* method on ``self`` --
9+
# e.g. ``self.on_progress_status(percent_complete)`` inside
10+
# ``on_progress_status``. Invoking any of them directly would recurse
11+
# forever, so they cannot be covered by a test. The tests below sidestep
12+
# the issue by overriding every callback in MockObserver. The recursive
13+
# bodies look like a production-code bug and have been flagged for review.
414
import time
515
import unittest
616

0 commit comments

Comments
 (0)