Skip to content

Commit

Permalink
More win fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
adiroiban committed May 24, 2023
1 parent afe7d0d commit ddd6aa3
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 28 deletions.
7 changes: 5 additions & 2 deletions src/chevah_compat/nt_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def _readLink(self, path):
handle, FSCTL_GET_REPARSE_POINT, None, 16 * 1024)
except pywintypes.error as error:
message = '%s - %s' % (error.winerror, error.strerror)
raise OSError(errno.EINVAL, message, path)
raise OSError(errno.EINVAL, message, encoded_path)
finally:
win32file.CloseHandle(handle)

Expand Down Expand Up @@ -814,7 +814,10 @@ def deleteFolder(self, segments, recursive=True):
else:
return os.rmdir(path_encoded)
except OSError as error:
# Windows return a generic EINVAL when path is not a folder.
# Sometimes windows return a generic EINVAL when path is not a
# folder.
# With Python3 we get ENOTDIR but with a different text
# message.
if error.errno == errno.EINVAL:
self._requireFolder(segments)
raise error
Expand Down
1 change: 1 addition & 0 deletions src/chevah_compat/testing/conditionals.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def onAdminPrivileges(present):
or ChevahTestCase.ci_name not in [
ChevahTestCase.CI.LOCAL,
ChevahTestCase.CI.BUILDBOT,
ChevahTestCase.CI.GITHUB,
]
)

Expand Down
29 changes: 22 additions & 7 deletions src/chevah_compat/tests/normal/test_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def test_create_home_folder(self):
When running under normal account, we can not create home folders
on Unix.
"""
if self.ci_name == self.CI.GITHUB:
raise self.skipTest('GHA always runs as super-admin')

result = self.capabilities.create_home_folder

self.assertFalse(result)
Expand All @@ -64,6 +67,9 @@ def test_getCurrentPrivilegesDescription(self):
"""
Check getCurrentPrivilegesDescription.
"""
if self.ci_name == self.CI.GITHUB:
raise self.skipTest('GHA always runs as super-admin')

text = self.capabilities.getCurrentPrivilegesDescription()

self.assertEqual(u'root capabilities disabled.', text)
Expand Down Expand Up @@ -202,6 +208,9 @@ def test_getPrivilegeState_present(self):
Return `absent` for privileges which are attached to current
process but are not enabled.
"""
if self.ci_name == self.CI.GITHUB:
raise self.skipTest('GHA always runs as super-admin')

result = self.capabilities._getPrivilegeState(
win32security.SE_SECURITY_NAME)

Expand All @@ -212,6 +221,9 @@ def test_getPrivilegeState_enabled_default(self):
Return `absent` for privileges which are attached to
current process but are not enabled by default.
"""
if self.ci_name == self.CI.GITHUB:
raise self.skipTest('GHA always runs as super-admin')

result = self.capabilities._getPrivilegeState(
win32security.SE_IMPERSONATE_NAME)

Expand All @@ -238,6 +250,9 @@ def test_symbolic_link(self):
"""
Not supported on Windows without elevated permissions.
"""
if self.ci_name == self.CI.GITHUB:
raise self.skipTest('GHA always runs as super-admin')

symbolic_link = self.capabilities.symbolic_link

self.assertFalse(symbolic_link)
Expand All @@ -246,6 +261,9 @@ def test_impersonate_local_account_windows(self):
"""
Impersonation is not available when running as a normal user.
"""
if self.ci_name == self.CI.GITHUB:
raise self.skipTest('GHA always runs as super-admin')

result = self.capabilities.impersonate_local_account

self.assertFalse(result)
Expand All @@ -257,13 +275,7 @@ def test_create_home_folder(self):
"""
result = self.capabilities.create_home_folder

if self.ci_name == self.CI.BUILDBOT and self.TEST_LANGUAGE != 'FR':
# Only buildbot slaves are setup with "Backup Operators"
# group (SE_BACKUP/SE_RESTORE) enabled.
# But not the I18N slave.
self.assertTrue(result)
else:
self.assertFalse(result)
self.assertFalse(result)

def test_getCurrentPrivilegesDescription(self):
"""
Expand Down Expand Up @@ -345,6 +357,9 @@ def test_isPrivilegeEnabled_enabled(self):
"""
Returns True for a privilege which is present and is enabled.
"""
if self.ci_name == self.CI.GITHUB:
raise self.skipTest('GHA always runs as super-admin')

# We use SE_IMPERSONATE privilege as it is enabled by default.
privilege = win32security.SE_IMPERSONATE_NAME

Expand Down
38 changes: 19 additions & 19 deletions src/chevah_compat/tests/normal/test_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,10 @@ def test_deleteFolder_file_non_recursive(self):

self.assertEqual(errno.ENOTDIR, context.exception.errno)
self.assertTrue(self.filesystem.exists(segments))
expected = '[Errno 20] Not a directory: ' + path
if self.os_family == 'nt':
expected = '[Errno 20] The directory name is invalid: ' + path
else:
expected = '[Errno 20] Not a directory: ' + path
self.assertEqual(expected, force_unicode(context.exception))

def test_deleteFolder_file_recursive(self):
Expand All @@ -384,7 +387,10 @@ def test_deleteFolder_file_recursive(self):

self.assertEqual(errno.ENOTDIR, context.exception.errno)
self.assertTrue(self.filesystem.exists(segments))
expected = '[Errno 20] Not a directory: ' + path
if self.os_family == 'nt':
expected = '[Errno 20] The directory name is invalid: ' + path
else:
expected = '[Errno 20] Not a directory: ' + path
self.assertEqual(expected, force_unicode(context.exception))

def test_deleteFolder_non_recursive_empty(self):
Expand Down Expand Up @@ -963,10 +969,10 @@ def test_getAttributes_link_not_found(self):

if self.TEST_LANGUAGE == 'FR':
expected_message = (
b'Le chemin d\x92acc\xe8s sp\xe9cifi\xe9 est introuvable')
'Le chemin d\x92acc\xe8s sp\xe9cifi\xe9 est introuvable')

elif self.os_family == 'nt':
expected_message = b'The system cannot find the path specified'
expected_message = 'The system cannot find the path specified'
else:
expected_message = 'No such file or directory'
self.assertEqual(errno.ENOENT, error.errno)
Expand Down Expand Up @@ -1027,12 +1033,11 @@ def test_getFolderContent_not_found(self):
if self.TEST_LANGUAGE == 'FR':
expected = (
'[Errno 2] Le chemin d\u2019acc\xe8s sp\xe9cifi\xe9 est '
'introuvable: ' + path + '\\*.*'
'introuvable: ' + path
)
elif self.os_name == 'windows':
expected = (
'[Errno 2] The system cannot find the path specified: '
+ path + '\\*.*'
'[Errno 2] The system cannot find the path specified: ' + path
)
else:
expected = '[Errno 2] No such file or directory: ' + path
Expand All @@ -1049,7 +1054,10 @@ def test_getFolderContent_file(self):
self.filesystem.getFolderContent(segments)

self.assertEqual(errno.ENOTDIR, context.exception.errno)
expected = '[Errno 20] Not a directory: ' + path
if self.os_family == 'nt':
expected = '[Errno 20] The directory name is invalid: ' + path
else:
expected = '[Errno 20] Not a directory: ' + path
self.assertEqual(expected, force_unicode(context.exception))

def test_getFolderContent_empty(self):
Expand Down Expand Up @@ -1118,23 +1126,15 @@ def test_iterateFolderContent_file(self):
with self.assertRaises(OSError) as context:
self.filesystem.iterateFolderContent(segments)

if self.os_family == 'nt':
# On Windows, we get a different error.
expected_error = errno.EINVAL
else:
expected_error = errno.ENOTDIR

self.assertEqual(expected_error, context.exception.errno)
self.assertEqual(errno.ENOTDIR, context.exception.errno)

if self.TEST_LANGUAGE == 'FR':
expected = (
'[Errno 22] Nom de r\xe9pertoire non valide: '
+ path
'[Errno 20] Nom de r\xe9pertoire non valide: ' + path
)
elif self.os_name == 'windows':
expected = (
'[Errno 22] The directory name is invalid: '
+ path
'[Errno 20] The directory name is invalid: ' + path
)
else:
expected = '[Errno 20] Not a directory: ' + path
Expand Down

0 comments on commit ddd6aa3

Please sign in to comment.