Skip to content

Commit

Permalink
Windows fix.
Browse files Browse the repository at this point in the history
Apparently `Path.is_absolute` and/or `Path.exists` can fail with
OSError with Python < 3.10 on Windows. The error didn't occur earlier
when we used `os.path` instead.
  • Loading branch information
pekkaklarck committed Apr 21, 2023
1 parent d973fb8 commit 8113352
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/robot/utils/filereader.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ def _get_path(self, source: Source, accept_text: bool):
if '\n' in source:
return None
path = Path(source)
if path.is_absolute() or path.exists():
return source
return None
try:
is_path = path.is_absolute() or path.exists()
except OSError:
is_path = False
return source if is_path else None

@property
def name(self) -> str:
Expand Down
9 changes: 7 additions & 2 deletions utest/utils/test_filereader.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,17 @@ def test_bytesio(self):
assert_reader(reader, '<in-memory file>')
assert_open(f)

def test_accept_text(self):
def test_text(self):
with FileReader(STRING, accept_text=True) as reader:
assert_reader(reader, '<in-memory file>')
assert_closed(reader.file)

def test_no_accept_text(self):
def test_text_with_special_chars(self):
for text in '!"#¤%&/()=?', '*** Test Cases ***', '':
with FileReader(text, accept_text=True) as reader:
assert_equal(reader.read(), text)

def test_text_when_text_is_not_accepted(self):
assert_raises(IOError, FileReader, STRING)

def test_readlines(self):
Expand Down

0 comments on commit 8113352

Please sign in to comment.