Skip to content
This repository was archived by the owner on Mar 27, 2026. It is now read-only.

Commit ce88c77

Browse files
committed
Refactor tests to remove unittest2 dependency
1 parent 54a8eb3 commit ce88c77

8 files changed

Lines changed: 249 additions & 267 deletions

File tree

dev-requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
flake8==3.8.4
22
black==20.8b1
33
pytest==6.1.2
4-
unittest2==1.1.0

emv/protocol/test/test_command.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
from __future__ import division, absolute_import, print_function, unicode_literals
2-
3-
# coding=utf-8
4-
from unittest2 import TestCase
51
from emv.protocol.command import (
62
CAPDU,
73
SelectCommand,
@@ -10,23 +6,22 @@
106
from emv.util import unformat_bytes
117

128

13-
class TestCAPDU(TestCase):
14-
def test_unmarshal(self):
15-
pdu = CAPDU.unmarshal(unformat_bytes("00 A4 04 00 07 A0 00 00 00 03 80 02"))
16-
self.assertIs(type(pdu), SelectCommand)
17-
self.assertEqual(pdu.p1, 0x04)
18-
self.assertEqual(pdu.p2, 0x00)
19-
self.assertEqual(len(pdu.data), 0x07)
20-
self.assertEqual(pdu.le, None)
9+
def test_unmarshal():
10+
pdu = CAPDU.unmarshal(unformat_bytes("00 A4 04 00 07 A0 00 00 00 03 80 02"))
11+
assert type(pdu) is SelectCommand
12+
assert pdu.p1 == 0x04
13+
assert pdu.p2 == 0x00
14+
assert len(pdu.data) == 0x07
15+
assert pdu.le is None
2116

22-
pdu = CAPDU.unmarshal(
23-
unformat_bytes(
24-
"""80 AE 80 00 1D 00 00 00 00 00 00 00 00 00 00 00 00
25-
00 00 80 00 00 00 00 00 00 01 01 01 00 00 00 00 00"""
26-
)
17+
pdu = CAPDU.unmarshal(
18+
unformat_bytes(
19+
"""80 AE 80 00 1D 00 00 00 00 00 00 00 00 00 00 00 00
20+
00 00 80 00 00 00 00 00 00 01 01 01 00 00 00 00 00"""
2721
)
28-
self.assertIs(type(pdu), GenerateApplicationCryptogramCommand)
29-
self.assertEqual(pdu.p1, 0x80)
30-
self.assertEqual(pdu.p2, 0x00)
31-
self.assertEqual(len(pdu.data), 0x1D)
32-
self.assertEqual(pdu.le, None)
22+
)
23+
assert type(pdu) is GenerateApplicationCryptogramCommand
24+
assert pdu.p1 == 0x80
25+
assert pdu.p2 == 0x00
26+
assert len(pdu.data) == 0x1D
27+
assert pdu.le is None
Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
from __future__ import division, absolute_import, print_function, unicode_literals
2-
3-
# coding=utf-8
4-
from unittest2 import TestCase
51
from emv.protocol.data_elements import ELEMENT_TABLE
62

73

8-
class TestDataElements(TestCase):
9-
def test_data_elements(self):
10-
# Test uniqueness of the main element table
11-
seen_tags = set()
12-
seen_shortnames = set()
13-
for tag, name, parse, shortname in ELEMENT_TABLE:
14-
self.assertNotIn(tag, seen_tags)
15-
if shortname is not None:
16-
self.assertNotIn(shortname, seen_shortnames)
17-
seen_shortnames.add(shortname)
18-
seen_tags.add(tag)
4+
def test_data_elements():
5+
# Test uniqueness of the main element table
6+
seen_tags = set()
7+
seen_shortnames = set()
8+
for tag, name, parse, shortname in ELEMENT_TABLE:
9+
assert tag not in seen_tags
10+
if shortname is not None:
11+
assert shortname not in seen_shortnames
12+
seen_shortnames.add(shortname)
13+
seen_tags.add(tag)

emv/protocol/test/test_response.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
# coding=utf-8
2-
from __future__ import division, absolute_import, print_function, unicode_literals
3-
from unittest2 import TestCase
1+
import pytest
42
from emv.protocol.response import RAPDU, SuccessResponse, WarningResponse, ErrorResponse
53

64

7-
class TestRAPDU(TestCase):
8-
def test_unmarshal(self):
9-
pdu = RAPDU.unmarshal([0x90, 0x00])
10-
self.assertIs(type(pdu), SuccessResponse)
5+
def test_unmarshal():
6+
pdu = RAPDU.unmarshal([0x90, 0x00])
7+
assert type(pdu) is SuccessResponse
118

12-
pdu = RAPDU.unmarshal([0x63, 0xC2])
13-
self.assertIs(type(pdu), WarningResponse)
9+
pdu = RAPDU.unmarshal([0x63, 0xC2])
10+
assert type(pdu) is WarningResponse
1411

15-
with self.assertRaises(ErrorResponse):
16-
RAPDU.unmarshal([0x6A, 0x81])
12+
with pytest.raises(ErrorResponse):
13+
RAPDU.unmarshal([0x6A, 0x81])

0 commit comments

Comments
 (0)