fix(fatfsgen): Fix incompatibility with the latest version of construct

This commit is contained in:
Roland Dobai 2024-01-10 09:47:34 +01:00 committed by BOT
parent 0717e0e4a3
commit d4d3e83d3c
2 changed files with 26 additions and 26 deletions

View File

@ -100,7 +100,7 @@ def remove_wear_levelling_if_exists(fs_: bytes) -> bytes:
boot_sector__.parse_boot_sector(fs_) boot_sector__.parse_boot_sector(fs_)
if boot_sector__.boot_sector_state.size == len(fs_): if boot_sector__.boot_sector_state.size == len(fs_):
return fs_ return fs_
except UnicodeDecodeError: except (UnicodeDecodeError, construct.core.StringError):
pass pass
plain_fs: bytes = remove_wl(fs_) plain_fs: bytes = remove_wl(fs_)
return plain_fs return plain_fs

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python #!/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 # SPDX-License-Identifier: Apache-2.0
import os import os
@ -32,13 +32,13 @@ class FatFSGen(unittest.TestCase):
@staticmethod @staticmethod
def test_gen_parse() -> None: def test_gen_parse() -> None:
run([ run([
'python', sys.executable,
f'{os.path.join(os.path.dirname(__file__), "..", "fatfsgen.py")}', f'{os.path.join(os.path.dirname(__file__), "..", "fatfsgen.py")}',
'output_data/tst_str' 'output_data/tst_str'
], stderr=STDOUT) ], stderr=STDOUT)
run(['python', '../fatfsgen.py', 'output_data/tst_str'], stderr=STDOUT) run([sys.executable, '../fatfsgen.py', 'output_data/tst_str'], stderr=STDOUT)
run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT) run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)
assert set(os.listdir('Espressif')) == {'TEST', 'TESTFILE'} assert set(os.listdir('Espressif')) == {'TEST', 'TESTFILE'}
with open('Espressif/TESTFILE', 'rb') as in_: 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_content(path_from_root=['WRITEF.TXT'], content=4096 * b'a' + b'a')
fatfs.write_filesystem('fatfs_image.img') 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_: with open('Espressif/WRITEF.TXT', 'rb') as in_:
assert in_.read() == 4097 * b'a' 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_content(path_from_root=['TESTFOLD', 'A255'], content=b'last')
fatfs.write_filesystem('fatfs_image.img') 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'}
assert set(os.listdir('Espressif/TESTFOLD')) == {f'A{str(i).upper()}' for i in range(256)} 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: def test_empty_fat16() -> None:
fatfs = fatfsgen.FATFS(size=17 * 1024 * 1024) fatfs = fatfsgen.FATFS(size=17 * 1024 * 1024)
fatfs.write_filesystem('fatfs_image.img') 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 @staticmethod
def test_chaining_fat16() -> None: def test_chaining_fat16() -> None:
@ -96,7 +96,7 @@ class FatFSGen(unittest.TestCase):
fatfs.create_file('WRITEF', extension='TXT') fatfs.create_file('WRITEF', extension='TXT')
fatfs.write_content(path_from_root=['WRITEF.TXT'], content=4096 * b'a' + b'a') fatfs.write_content(path_from_root=['WRITEF.TXT'], content=4096 * b'a' + b'a')
fatfs.write_filesystem('fatfs_image.img') 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_: with open('Espressif/WRITEF.TXT', 'rb') as in_:
assert in_.read() == 4097 * b'a' 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', 'A0'], content=b'first')
fatfs.write_content(path_from_root=['TESTFOLD', 'A126'], content=b'later') fatfs.write_content(path_from_root=['TESTFOLD', 'A126'], content=b'later')
fatfs.write_filesystem('fatfs_image.img') 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'}
assert set(os.listdir('Espressif/TESTFOLD')) == {f'A{str(i).upper()}' for i in range(128)} assert set(os.listdir('Espressif/TESTFOLD')) == {f'A{str(i).upper()}' for i in range(128)}
with open('Espressif/TESTFOLD/A0', 'rb') as in_: with open('Espressif/TESTFOLD/A0', 'rb') as in_:
@ -134,20 +134,20 @@ class FatFSGen(unittest.TestCase):
} }
generate_local_folder_structure(struct_, path_='.') generate_local_folder_structure(struct_, path_='.')
run([ run([
'python', sys.executable,
f'{os.path.join(os.path.dirname(__file__), "..", "fatfsgen.py")}', f'{os.path.join(os.path.dirname(__file__), "..", "fatfsgen.py")}',
'testf' 'testf'
], stderr=STDOUT) ], 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') assert compare_folders('testf', 'Espressif')
shutil.rmtree('Espressif', ignore_errors=True) shutil.rmtree('Espressif', ignore_errors=True)
run([ run([
'python', sys.executable,
f'{os.path.join(os.path.dirname(__file__), "..", "wl_fatfsgen.py")}', f'{os.path.join(os.path.dirname(__file__), "..", "wl_fatfsgen.py")}',
'testf' 'testf'
], stderr=STDOUT) ], 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') assert compare_folders('testf', 'Espressif')
def test_e2e_deeper(self) -> None: def test_e2e_deeper(self) -> None:
@ -173,20 +173,20 @@ class FatFSGen(unittest.TestCase):
generate_local_folder_structure(struct_, path_='.') generate_local_folder_structure(struct_, path_='.')
run([ run([
'python', sys.executable,
f'{os.path.join(os.path.dirname(__file__), "..", "fatfsgen.py")}', f'{os.path.join(os.path.dirname(__file__), "..", "fatfsgen.py")}',
'testf' 'testf'
], stderr=STDOUT) ], 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') assert compare_folders('testf', 'Espressif')
shutil.rmtree('Espressif', ignore_errors=True) shutil.rmtree('Espressif', ignore_errors=True)
run([ run([
'python', sys.executable,
f'{os.path.join(os.path.dirname(__file__), "..", "wl_fatfsgen.py")}', f'{os.path.join(os.path.dirname(__file__), "..", "wl_fatfsgen.py")}',
'testf' 'testf'
], stderr=STDOUT) ], 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') assert compare_folders('testf', 'Espressif')
def test_e2e_deeper_large(self) -> None: def test_e2e_deeper_large(self) -> None:
@ -229,20 +229,20 @@ class FatFSGen(unittest.TestCase):
} }
generate_local_folder_structure(struct_, path_='.') generate_local_folder_structure(struct_, path_='.')
run([ run([
'python', sys.executable,
f'{os.path.join(os.path.dirname(__file__), "..", "fatfsgen.py")}', f'{os.path.join(os.path.dirname(__file__), "..", "fatfsgen.py")}',
'testf' 'testf'
], stderr=STDOUT) ], 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') assert compare_folders('testf', 'Espressif')
shutil.rmtree('Espressif', ignore_errors=True) shutil.rmtree('Espressif', ignore_errors=True)
run([ run([
'python', sys.executable,
f'{os.path.join(os.path.dirname(__file__), "..", "wl_fatfsgen.py")}', f'{os.path.join(os.path.dirname(__file__), "..", "wl_fatfsgen.py")}',
'testf' 'testf'
], stderr=STDOUT) ], 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') assert compare_folders('testf', 'Espressif')
def test_e2e_very_deep(self) -> None: def test_e2e_very_deep(self) -> None:
@ -287,11 +287,11 @@ class FatFSGen(unittest.TestCase):
} }
generate_local_folder_structure(struct_, path_='.') generate_local_folder_structure(struct_, path_='.')
run([ run([
'python', sys.executable,
f'{os.path.join(os.path.dirname(__file__), "..", "fatfsgen.py")}', f'{os.path.join(os.path.dirname(__file__), "..", "fatfsgen.py")}',
'testf' 'testf'
], stderr=STDOUT) ], 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') assert compare_folders('testf', 'Espressif')
def test_e2e_very_deep_long(self) -> None: def test_e2e_very_deep_long(self) -> None:
@ -317,11 +317,11 @@ class FatFSGen(unittest.TestCase):
} }
generate_local_folder_structure(struct_, path_='.') generate_local_folder_structure(struct_, path_='.')
run([ run([
'python', sys.executable,
f'{os.path.join(os.path.dirname(__file__), "..", "fatfsgen.py")}', f'{os.path.join(os.path.dirname(__file__), "..", "fatfsgen.py")}',
'testf', '--long_name_support' 'testf', '--long_name_support'
], stderr=STDOUT) ], 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') assert compare_folders('testf', 'Espressif')
def test_parse_long_name(self) -> None: def test_parse_long_name(self) -> None: