File: test_PCSC.py

package info (click to toggle)
pyscard 2.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,348 kB
  • sloc: python: 8,718; ansic: 1,971; makefile: 51; sh: 7
file content (30 lines) | stat: -rw-r--r-- 822 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# pylint: disable=missing-module-docstring
# pylint: disable=invalid-name
# pylint: disable=missing-function-docstring

from smartcard.scard import (
    SCARD_E_NO_READERS_AVAILABLE,
    SCARD_E_NO_SERVICE,
    SCARD_S_SUCCESS,
    SCARD_SCOPE_USER,
    SCardEstablishContext,
    SCardListReaders,
    SCardReleaseContext,
)


def test_low_level():
    hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER)
    assert hresult in (SCARD_S_SUCCESS, SCARD_E_NO_SERVICE)

    if hresult == SCARD_E_NO_SERVICE:
        return

    hresult, _ = SCardListReaders(hcontext, [])
    assert hresult in (SCARD_S_SUCCESS, SCARD_E_NO_READERS_AVAILABLE)

    # the computer we are using may not have a reader connected
    # so we can't do much

    hresult = SCardReleaseContext(hcontext)
    assert hresult == SCARD_S_SUCCESS