Skip to content

Commit e64f576

Browse files
Issue #198 Fix bug introduced in previous commit: tests/rest/auth/test_config.py:163: AttributeError
AttributeError: 'function' object has no attribute 'st_mode'
1 parent af9f9b3 commit e64f576

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

openeo/rest/auth/config.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def assert_private_file(path: Path):
2929
"""Check that given file is only readable by user."""
3030

3131
# use oschmod on Windows
32+
# TODO: can we use oschmod for all operating systems, make the code simpler and consitent?
3233
if platform.system() == "Windows":
3334
mode = oschmod.get_mode(str(path))
3435
else:
@@ -38,10 +39,6 @@ def assert_private_file(path: Path):
3839
p=path, a=mode & (stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO), e=_PRIVATE_PERMS
3940
)
4041
raise PermissionError(message)
41-
# if platform.system() == 'Windows':
42-
# log.info(message)
43-
# else:
44-
# raise PermissionError(message)
4542

4643

4744
def utcnow_rfc3339() -> str:
@@ -94,7 +91,8 @@ def _write(self, data: dict):
9491
# TODO: add file locking to avoid race conditions?
9592
with self._path.open("w", encoding="utf8") as f:
9693
json.dump(data, f, indent=2)
97-
# on Windows us oschmod because Python chmod implementation doesn't work on Windows.
94+
# On Windows we use oschmod because Python chmod implementation doesn't work on Windows.
95+
# TODO: can we use oschmod on all platforms? Seems like that is the intention of oschmod.
9896
if platform.system() == "Windows":
9997
oschmod.set_mode(str(self._path), mode=_PRIVATE_PERMS)
10098
else:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
'xarray>=0.12.3',
4848
'pandas>0.20.0',
4949
'deprecated>=1.2.12',
50-
'oschmod; sys_platform == "win32"',
50+
'oschmod',
5151
'pywin32; sys_platform == "win32"',
5252
],
5353
extras_require={

tests/rest/auth/test_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def test_permissions(self, tmp_path):
160160
if platform.system() == 'Windows':
161161
st_mode = oschmod.get_mode(str(token_path))
162162
else:
163-
token_path.stat.st_mode()
163+
token_path.stat().st_mode
164164
st_mode = (tmp_path / RefreshTokenStore.DEFAULT_FILENAME).stat().st_mode
165165
assert st_mode & 0o777 == 0o600
166166

tests/test_config.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import contextlib
22
import logging
33
import os
4+
import platform
45
import random
56
import re
67
import textwrap
@@ -159,9 +160,9 @@ def test_get_config_verbose(tmp_path, caplog, capsys, verbose, force_interactive
159160
config = get_config()
160161
assert config.get("general.verbose") == verbose
161162

162-
# TODO: on Windows the path in config_path makes the regex invalid.
163-
# My guess is the \ from the path is interpreted as an escape sequence
164-
import platform
163+
# On Windows the path in config_path would make the regex invalid because
164+
# windows paths contain \ and a regex interprets that as an escape sequence.
165+
# Therefore we have to escape the \ to \\ .
165166
if platform.system() == "Windows":
166167
config_path_escaped = str(config_path).replace("\\", "\\\\")
167168
else:

0 commit comments

Comments
 (0)