Skip to content

Commit

Permalink
[8DOT3] Improve test coverage, removing unused exception handling
Browse files Browse the repository at this point in the history
os.path.splitext always returns a tuple with two elements, so IndexError
cannot be raised.
  • Loading branch information
nathanhi committed Jun 11, 2023
1 parent ae8af20 commit c8b4f30
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions pyfatfs/EightDotThree.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,23 +214,17 @@ def map_chars(name: bytes) -> bytes:
return _name

dir_name = dir_name.upper()
try:
# Shorten to 8 chars; strip invalid characters
basename = os.path.splitext(dir_name)[0][0:8].strip()
basename = basename.encode(parent_dir_entry._encoding,
errors="replace")
basename = map_chars(basename).decode(parent_dir_entry._encoding)
except IndexError:
basename = ""

try:
# Shorten to 3 chars; strip invalid characters
extname = os.path.splitext(dir_name)[1][1:4].strip()
extname = extname.encode(parent_dir_entry._encoding,
errors="replace")
extname = map_chars(extname).decode(parent_dir_entry._encoding)
except IndexError:
extname = ""
# Shorten to 8 chars; strip invalid characters
basename = os.path.splitext(dir_name)[0][0:8].strip()
basename = basename.encode(parent_dir_entry._encoding,
errors="replace")
basename = map_chars(basename).decode(parent_dir_entry._encoding)

# Shorten to 3 chars; strip invalid characters
extname = os.path.splitext(dir_name)[1][1:4].strip()
extname = extname.encode(parent_dir_entry._encoding,
errors="replace")
extname = map_chars(extname).decode(parent_dir_entry._encoding)

if len(extname) == 0:
extsep = ""
Expand Down

0 comments on commit c8b4f30

Please sign in to comment.