Skip to content

Commit

Permalink
test: check error strings returned on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
LudovicRousseau committed Apr 23, 2023
1 parent 0d51b2a commit 34118d3
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions test/test_Exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ def test_ListReadersException(self):
exc = ListReadersException(0)
self.assertEqual(exc.hresult, 0)
text = str(exc)
if platform.system() != 'Windows':
self.assertEqual(text, "Failed to list readers: Command successful. (0x00000000)")
if platform.system() == 'Windows':
expected = "Failed to list readers: The operation completed successfully. (0x00000000)"
else:
expected = "Failed to list readers: Command successful. (0x00000000)"
self.assertEqual(text, expected)

exc = ListReadersException(0x42)
self.assertEqual(exc.hresult, 0x42)
text = str(exc)
if platform.system() != 'Windows':
expected = "Failed to list readers: Unknown error: 0x00000042 (0x00000042)"
macos_bug_expected = expected.replace("Unknown", "Unkown")
print(expected, macos_bug_expected)
self.assertIn(text, [expected, macos_bug_expected])

exc = ListReadersException(SCARD_S_SUCCESS)
Expand All @@ -40,8 +42,12 @@ def test_ListReadersException(self):
exc = ListReadersException(SCARD_E_NO_SERVICE)
self.assertEqual(exc.hresult, SCARD_E_NO_SERVICE)
text = str(exc)
if platform.system() != 'Windows':
self.assertEqual(text, "Failed to list readers: Service not available. (0x8010001D)")
if platform.system() == 'Windows':
expected = "Failed to list readers: The Smart Card Resource Manager is not running. (0x8010001D)"
else:
expected = "Failed to list readers: Service not available. (0x8010001D)"

self.assertEqual(text, expected)

def test_NoReadersException(self):
exc = NoReadersException()
Expand All @@ -64,7 +70,12 @@ def test_CardConnectionException(self):
exc = CardConnectionException("foo", SCARD_W_REMOVED_CARD)
self.assertEqual(exc.hresult, SCARD_W_REMOVED_CARD)
text = str(exc)
self.assertEqual(text, "foo: Card was removed. (0x80100069)")
if platform.system() == 'Windows':
expected = "foo: The smart card has been removed, so that further communication is not possible. (0x80100069)"
else:
expected = "foo: Card was removed. (0x80100069)"

self.assertEqual(text, expected)

def test_hresult(self):
hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER)
Expand Down

0 comments on commit 34118d3

Please sign in to comment.