From d4d3e83d3c34e43a232cb8e8ea96fd3a66edb447 Mon Sep 17 00:00:00 2001 From: Roland Dobai Date: Wed, 10 Jan 2024 09:47:34 +0100 Subject: [PATCH] fix(fatfsgen): Fix incompatibility with the latest version of construct --- components/fatfs/fatfsparse.py | 2 +- .../fatfs/test_fatfsgen/test_fatfsparse.py | 50 +++++++++---------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/components/fatfs/fatfsparse.py b/components/fatfs/fatfsparse.py index 6eab1ff7cb..13c9a0565c 100755 --- a/components/fatfs/fatfsparse.py +++ b/components/fatfs/fatfsparse.py @@ -100,7 +100,7 @@ def remove_wear_levelling_if_exists(fs_: bytes) -> bytes: boot_sector__.parse_boot_sector(fs_) if boot_sector__.boot_sector_state.size == len(fs_): return fs_ - except UnicodeDecodeError: + except (UnicodeDecodeError, construct.core.StringError): pass plain_fs: bytes = remove_wl(fs_) return plain_fs diff --git a/components/fatfs/test_fatfsgen/test_fatfsparse.py b/components/fatfs/test_fatfsgen/test_fatfsparse.py index 15a7f3d866..43d62eb5d1 100755 --- a/components/fatfs/test_fatfsgen/test_fatfsparse.py +++ b/components/fatfs/test_fatfsgen/test_fatfsparse.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Apache-2.0 import os @@ -32,13 +32,13 @@ class FatFSGen(unittest.TestCase): @staticmethod def test_gen_parse() -> None: run([ - 'python', + sys.executable, f'{os.path.join(os.path.dirname(__file__), "..", "fatfsgen.py")}', 'output_data/tst_str' ], stderr=STDOUT) - run(['python', '../fatfsgen.py', 'output_data/tst_str'], stderr=STDOUT) - run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) + run([sys.executable, '../fatfsgen.py', 'output_data/tst_str'], stderr=STDOUT) + run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) assert set(os.listdir('Espressif')) == {'TEST', 'TESTFILE'} with open('Espressif/TESTFILE', 'rb') as in_: @@ -59,7 +59,7 @@ class FatFSGen(unittest.TestCase): fatfs.write_content(path_from_root=['WRITEF.TXT'], content=4096 * b'a' + b'a') fatfs.write_filesystem('fatfs_image.img') - run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) + run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) with open('Espressif/WRITEF.TXT', 'rb') as in_: assert in_.read() == 4097 * b'a' @@ -74,7 +74,7 @@ class FatFSGen(unittest.TestCase): fatfs.write_content(path_from_root=['TESTFOLD', 'A255'], content=b'last') fatfs.write_filesystem('fatfs_image.img') - run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) + run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) assert set(os.listdir('Espressif')) == {'TESTFOLD'} assert set(os.listdir('Espressif/TESTFOLD')) == {f'A{str(i).upper()}' for i in range(256)} @@ -88,7 +88,7 @@ class FatFSGen(unittest.TestCase): def test_empty_fat16() -> None: fatfs = fatfsgen.FATFS(size=17 * 1024 * 1024) fatfs.write_filesystem('fatfs_image.img') - run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) + run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) @staticmethod def test_chaining_fat16() -> None: @@ -96,7 +96,7 @@ class FatFSGen(unittest.TestCase): fatfs.create_file('WRITEF', extension='TXT') fatfs.write_content(path_from_root=['WRITEF.TXT'], content=4096 * b'a' + b'a') fatfs.write_filesystem('fatfs_image.img') - run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) + run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) with open('Espressif/WRITEF.TXT', 'rb') as in_: assert in_.read() == 4097 * b'a' @@ -109,7 +109,7 @@ class FatFSGen(unittest.TestCase): fatfs.write_content(path_from_root=['TESTFOLD', 'A0'], content=b'first') fatfs.write_content(path_from_root=['TESTFOLD', 'A126'], content=b'later') fatfs.write_filesystem('fatfs_image.img') - run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) + run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) assert set(os.listdir('Espressif')) == {'TESTFOLD'} assert set(os.listdir('Espressif/TESTFOLD')) == {f'A{str(i).upper()}' for i in range(128)} with open('Espressif/TESTFOLD/A0', 'rb') as in_: @@ -134,20 +134,20 @@ class FatFSGen(unittest.TestCase): } generate_local_folder_structure(struct_, path_='.') run([ - 'python', + sys.executable, f'{os.path.join(os.path.dirname(__file__), "..", "fatfsgen.py")}', 'testf' ], stderr=STDOUT) - run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) + run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) assert compare_folders('testf', 'Espressif') shutil.rmtree('Espressif', ignore_errors=True) run([ - 'python', + sys.executable, f'{os.path.join(os.path.dirname(__file__), "..", "wl_fatfsgen.py")}', 'testf' ], stderr=STDOUT) - run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) + run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) assert compare_folders('testf', 'Espressif') def test_e2e_deeper(self) -> None: @@ -173,20 +173,20 @@ class FatFSGen(unittest.TestCase): generate_local_folder_structure(struct_, path_='.') run([ - 'python', + sys.executable, f'{os.path.join(os.path.dirname(__file__), "..", "fatfsgen.py")}', 'testf' ], stderr=STDOUT) - run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) + run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) assert compare_folders('testf', 'Espressif') shutil.rmtree('Espressif', ignore_errors=True) run([ - 'python', + sys.executable, f'{os.path.join(os.path.dirname(__file__), "..", "wl_fatfsgen.py")}', 'testf' ], stderr=STDOUT) - run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) + run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) assert compare_folders('testf', 'Espressif') def test_e2e_deeper_large(self) -> None: @@ -229,20 +229,20 @@ class FatFSGen(unittest.TestCase): } generate_local_folder_structure(struct_, path_='.') run([ - 'python', + sys.executable, f'{os.path.join(os.path.dirname(__file__), "..", "fatfsgen.py")}', 'testf' ], stderr=STDOUT) - run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) + run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) assert compare_folders('testf', 'Espressif') shutil.rmtree('Espressif', ignore_errors=True) run([ - 'python', + sys.executable, f'{os.path.join(os.path.dirname(__file__), "..", "wl_fatfsgen.py")}', 'testf' ], stderr=STDOUT) - run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) + run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) assert compare_folders('testf', 'Espressif') def test_e2e_very_deep(self) -> None: @@ -287,11 +287,11 @@ class FatFSGen(unittest.TestCase): } generate_local_folder_structure(struct_, path_='.') run([ - 'python', + sys.executable, f'{os.path.join(os.path.dirname(__file__), "..", "fatfsgen.py")}', 'testf' ], stderr=STDOUT) - run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) + run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) assert compare_folders('testf', 'Espressif') def test_e2e_very_deep_long(self) -> None: @@ -317,11 +317,11 @@ class FatFSGen(unittest.TestCase): } generate_local_folder_structure(struct_, path_='.') run([ - 'python', + sys.executable, f'{os.path.join(os.path.dirname(__file__), "..", "fatfsgen.py")}', 'testf', '--long_name_support' ], stderr=STDOUT) - run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) + run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) assert compare_folders('testf', 'Espressif') def test_parse_long_name(self) -> None: