From 9d989e4d8bb43d30afe2b4da228801d1024d6477 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 15 Apr 2026 11:14:51 -0400 Subject: [PATCH] tests: Remove further trailing spaces when possible. Most cases here have `print(..., some_str)` changed to `print(..., repr(some_str))`. This makes the empty string visible and prevents bare trailing spaces. Signed-off-by: Dan Halbert --- tests/basics/string_tstring_basic.py | 3 +- tests/basics/string_tstring_basic.py.exp | 2 +- tests/cmdline/repl_paste.py | 12 +++--- tests/extmod/vfs_basic.py | 16 +++---- tests/extmod/vfs_basic.py.exp | 42 +++++++++---------- tests/micropython/heapalloc_traceback.py | 6 +-- tests/micropython/heapalloc_traceback.py.exp | 8 ++-- .../heapalloc_traceback.py.native.exp | 4 +- tests/ports/esp32/check_err_str.py | 2 +- tests/ports/esp32/check_err_str.py.exp | 2 +- tests/thread/thread_exc2.py.exp | 2 +- tests/thread/thread_exc2.py.native.exp | 2 +- 12 files changed, 51 insertions(+), 50 deletions(-) diff --git a/tests/basics/string_tstring_basic.py b/tests/basics/string_tstring_basic.py index e23a3f0659..aa9de327b5 100644 --- a/tests/basics/string_tstring_basic.py +++ b/tests/basics/string_tstring_basic.py @@ -172,7 +172,8 @@ print(f" Value: {t_nested_expr.interpolations[0].value}") print("\n=== Interpolation attribute tests ===") i_basic = Interpolation(42, "x") print(f"Basic conversion: {i_basic.conversion}") -print(f"Basic format_spec: {i_basic.format_spec}") +# Put in quotes to make empty string visible. +print(f"Basic format_spec: '{i_basic.format_spec}'") i_with_conv = Interpolation(42, "x", "s") print(f"With conversion: {i_with_conv.conversion}") diff --git a/tests/basics/string_tstring_basic.py.exp b/tests/basics/string_tstring_basic.py.exp index 4fcb3a7583..60affaad49 100644 --- a/tests/basics/string_tstring_basic.py.exp +++ b/tests/basics/string_tstring_basic.py.exp @@ -71,7 +71,7 @@ Nested expr: Template(strings=('', ''), interpolations=(Interpolation('{}', 'inn === Interpolation attribute tests === Basic conversion: None -Basic format_spec: +Basic format_spec: '' With conversion: s With format_spec: :>10 Full conversion: r diff --git a/tests/cmdline/repl_paste.py b/tests/cmdline/repl_paste.py index 7cec450fce..8c4f341701 100644 --- a/tests/cmdline/repl_paste.py +++ b/tests/cmdline/repl_paste.py @@ -26,10 +26,10 @@ calculate(5) {\x05} def function_with_blanks(): print('First line') - +{\x20}{\x20}{\x20}{\x20} print('After blank line') - - +{\x20}{\x20}{\x20}{\x20} +{\x20}{\x20}{\x20}{\x20} print('After two blank lines') function_with_blanks() @@ -40,10 +40,10 @@ function_with_blanks() class TestClass: def __init__(self, value): self.value = value - +{\x20}{\x20}{\x20}{\x20} def display(self): print(f'Value is: {self.value}') - +{\x20}{\x20}{\x20}{\x20} def double(self): self.value *= 2 return self.value @@ -82,7 +82,7 @@ def bad_syntax(: {\x05} def will_error(): undefined_variable - +{\x20}{\x20}{\x20}{\x20} will_error() {\x04} diff --git a/tests/extmod/vfs_basic.py b/tests/extmod/vfs_basic.py index 2c0ce8f529..09fe5dce02 100644 --- a/tests/extmod/vfs_basic.py +++ b/tests/extmod/vfs_basic.py @@ -19,11 +19,11 @@ class Filesystem: print(self.id, "umount") def ilistdir(self, dir): - print(self.id, "ilistdir", dir) + print(self.id, "ilistdir", repr(dir)) return iter([("a%d" % self.id, 0, 0)]) def chdir(self, dir): - print(self.id, "chdir", dir) + print(self.id, "chdir", repr(dir)) if self.fail: raise OSError(self.fail) @@ -32,23 +32,23 @@ class Filesystem: return "dir%d" % self.id def mkdir(self, path): - print(self.id, "mkdir", path) + print(self.id, "mkdir", repr(path)) def remove(self, path): - print(self.id, "remove", path) + print(self.id, "remove", repr(path)) def rename(self, old_path, new_path): - print(self.id, "rename", old_path, new_path) + print(self.id, "rename", repr(old_path), repr(new_path)) def rmdir(self, path): - print(self.id, "rmdir", path) + print(self.id, "rmdir", repr(path)) def stat(self, path): - print(self.id, "stat", path) + print(self.id, "stat", repr(path)) return (self.id,) def statvfs(self, path): - print(self.id, "statvfs", path) + print(self.id, "statvfs", repr(path)) return (self.id,) def open(self, file, mode): diff --git a/tests/extmod/vfs_basic.py.exp b/tests/extmod/vfs_basic.py.exp index 536bb4c805..a03176a3c4 100644 --- a/tests/extmod/vfs_basic.py.exp +++ b/tests/extmod/vfs_basic.py.exp @@ -18,30 +18,30 @@ stat /x OSError ('test_mnt', 16384, 0) StopIteration StopIteration -1 ilistdir / +1 ilistdir '/' ['a1'] -1 ilistdir / +1 ilistdir '/' ['a1'] 2 mount True False ['test_mnt', 'test_mnt2'] -2 ilistdir / +2 ilistdir '/' ['a2'] 3 mount False False OSError OSError OSError -1 chdir / -1 ilistdir +1 chdir '/' +1 ilistdir '' ['a1'] 1 getcwd /test_mntdir1 -1 mkdir test_dir -1 remove test_file -1 rename test_file test_file2 -1 rmdir test_dir -1 stat test_file +1 mkdir 'test_dir' +1 remove 'test_file' +1 rename 'test_file' 'test_file2' +1 rmdir 'test_dir' +1 stat 'test_file' (1,) -1 statvfs / +1 statvfs '/' (1,) 1 open test_file r 1 open test_file wb @@ -50,29 +50,29 @@ OSError OSError 3 mount False False (16384, 0, 0, 0, 0, 0, 0, 0, 0, 0) -3 statvfs / +3 statvfs '/' (3,) -3 ilistdir / +3 ilistdir '/' ['a3'] 3 open test r 4 mount False False -3 ilistdir / +3 ilistdir '/' ['mnt', 'a3'] -4 ilistdir / +4 ilistdir '/' ['a4'] -4 chdir / -4 ilistdir +4 chdir '/' +4 ilistdir '' ['a4'] -3 chdir /subdir -3 ilistdir +3 chdir '/subdir' +3 ilistdir '' ['a3'] -3 chdir / +3 chdir '/' 3 umount ['mnt'] 4 umount OSError / 5 mount False False -5 chdir /subdir +5 chdir '/subdir' OSError / diff --git a/tests/micropython/heapalloc_traceback.py b/tests/micropython/heapalloc_traceback.py index 1743d4956d..89fa37a48c 100644 --- a/tests/micropython/heapalloc_traceback.py +++ b/tests/micropython/heapalloc_traceback.py @@ -30,13 +30,13 @@ def test(): # call test() with heap allocation disabled test() -# print the exception that was raised +# print the exception that was raised. Use repr() to make the whitespace visible. buf = io.StringIO() sys.print_exception(global_exc, buf) for l in buf.getvalue().split("\n"): # MicroPython on pyboard prints as file, so remove filename. if l.startswith(" File "): l = l.split('"') - print(l[0], l[2]) + print(repr(l[0]), repr(l[2])) else: - print(l) + print(repr(l)) diff --git a/tests/micropython/heapalloc_traceback.py.exp b/tests/micropython/heapalloc_traceback.py.exp index e0799aa2b3..fa30fa2208 100644 --- a/tests/micropython/heapalloc_traceback.py.exp +++ b/tests/micropython/heapalloc_traceback.py.exp @@ -1,5 +1,5 @@ StopIteration -Traceback (most recent call last): - File , line 24, in test -StopIteration: - +'Traceback (most recent call last):' +' File ' ', line 24, in test' +'StopIteration: ' +'' diff --git a/tests/micropython/heapalloc_traceback.py.native.exp b/tests/micropython/heapalloc_traceback.py.native.exp index d6ac26aa82..851eb5c780 100644 --- a/tests/micropython/heapalloc_traceback.py.native.exp +++ b/tests/micropython/heapalloc_traceback.py.native.exp @@ -1,3 +1,3 @@ StopIteration -StopIteration: - +'StopIteration: ' +'' diff --git a/tests/ports/esp32/check_err_str.py b/tests/ports/esp32/check_err_str.py index 9efe1afa19..598db4e1e1 100644 --- a/tests/ports/esp32/check_err_str.py +++ b/tests/ports/esp32/check_err_str.py @@ -32,7 +32,7 @@ try: except OSError as e: exc = e micropython.heap_unlock() -print("exc:", exc) # exc empty due to no memory +print("exc:", repr(exc)) # exc empty due to no memory # same again but having an emergency buffer micropython.alloc_emergency_exception_buf(256) diff --git a/tests/ports/esp32/check_err_str.py.exp b/tests/ports/esp32/check_err_str.py.exp index d4162d1be0..db45d49255 100644 --- a/tests/ports/esp32/check_err_str.py.exp +++ b/tests/ports/esp32/check_err_str.py.exp @@ -1,4 +1,4 @@ [Errno 2] ENOENT (-5379, 'ESP_ERR_OTA_VALIDATE_FAILED') -exc: +exc: OSError() -5379 diff --git a/tests/thread/thread_exc2.py.exp b/tests/thread/thread_exc2.py.exp index 469516dacc..b7085c7af9 100644 --- a/tests/thread/thread_exc2.py.exp +++ b/tests/thread/thread_exc2.py.exp @@ -1,5 +1,5 @@ Unhandled exception in thread started by Traceback (most recent call last): File \.\+, line 7, in thread_entry -ValueError: +ValueError: \$ done diff --git a/tests/thread/thread_exc2.py.native.exp b/tests/thread/thread_exc2.py.native.exp index 9b2e715ef8..8188dd3ed0 100644 --- a/tests/thread/thread_exc2.py.native.exp +++ b/tests/thread/thread_exc2.py.native.exp @@ -1,3 +1,3 @@ Unhandled exception in thread started by -ValueError: +ValueError: \$ done