Skip to content

Commit 5103e35

Browse files
committed
modernize test cases
1 parent ccc1380 commit 5103e35

19 files changed

+20
-83
lines changed

test/back2back_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
This module tests two virtual buses attached to each other.
66
"""
77

8-
from __future__ import absolute_import, print_function
9-
108
import sys
119
import unittest
1210
from time import sleep

test/listener_test.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
"""
55
"""
66

7-
from __future__ import absolute_import, print_function
8-
97
from time import sleep
108
import unittest
119
import random
@@ -117,7 +115,7 @@ def test_filetype_to_instance(extension, klass):
117115
test_filetype_to_instance(".log", can.CanutilsLogReader)
118116

119117
# test file extensions that are not supported
120-
with self.assertRaisesRegexp(NotImplementedError, ".xyz_42"):
118+
with self.assertRaisesRegex(NotImplementedError, ".xyz_42"):
121119
test_filetype_to_instance(".xyz_42", can.Printer)
122120

123121
def testLoggerTypeResolution(self):

test/logformats_test.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,12 @@
1414
TODO: implement CAN FD support testing
1515
"""
1616

17-
from __future__ import print_function, absolute_import, division
18-
1917
import logging
2018
import unittest
2119
import tempfile
2220
import os
2321
from abc import abstractmethod, ABCMeta
24-
25-
try:
26-
# Python 3
27-
from itertools import zip_longest
28-
except ImportError:
29-
# Python 2
30-
from itertools import izip_longest as zip_longest
22+
from itertools import zip_longest
3123

3224
import can
3325

@@ -39,7 +31,7 @@
3931
logging.basicConfig(level=logging.DEBUG)
4032

4133

42-
class ReaderWriterTest(unittest.TestCase, ComparingMessagesTestCase):
34+
class ReaderWriterTest(unittest.TestCase, ComparingMessagesTestCase, metaclass=ABCMeta):
4335
"""Tests a pair of writer and reader by writing all data first and
4436
then reading all data and checking if they could be reconstructed
4537
correctly. Optionally writes some comments as well.
@@ -50,8 +42,6 @@ class ReaderWriterTest(unittest.TestCase, ComparingMessagesTestCase):
5042
(Source: `*Wojciech B.* on StackOverlfow <https://stackoverflow.com/a/22836015/3753684>`_)
5143
"""
5244

53-
__metaclass__ = ABCMeta
54-
5545
def __init__(self, *args, **kwargs):
5646
unittest.TestCase.__init__(self, *args, **kwargs)
5747
self._setup_instance()

test/message_helper.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
This module contains a helper for writing test cases that need to compare messages.
66
"""
77

8-
from __future__ import absolute_import, print_function
9-
108
from copy import copy
119

1210

13-
class ComparingMessagesTestCase(object):
11+
class ComparingMessagesTestCase:
1412
"""
1513
Must be extended by a class also extending a unittest.TestCase.
1614

test/network_test.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
#!/usr/bin/env python
22
# coding: utf-8
33

4-
from __future__ import print_function
54

65
import unittest
76
import threading
8-
try:
9-
import queue
10-
except ImportError:
11-
import Queue as queue
7+
import queue
128
import random
13-
149
import logging
10+
1511
logging.getLogger(__file__).setLevel(logging.WARNING)
1612

1713
# make a random bool:

test/notifier_test.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33

44
import unittest
55
import time
6-
try:
7-
import asyncio
8-
except ImportError:
9-
asyncio = None
6+
import asyncio
107

118
import can
129

@@ -45,7 +42,6 @@ def test_multiple_bus(self):
4542

4643
class AsyncNotifierTest(unittest.TestCase):
4744

48-
@unittest.skipIf(asyncio is None, 'Test requires asyncio')
4945
def test_asyncio_notifier(self):
5046
loop = asyncio.get_event_loop()
5147
bus = can.Bus('test', bustype='virtual', receive_own_messages=True)
@@ -60,6 +56,5 @@ def test_asyncio_notifier(self):
6056
bus.shutdown()
6157

6258

63-
6459
if __name__ == '__main__':
6560
unittest.main()

test/serial_test.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
Copyright: 2017 Boris Wenzlaff
88
"""
99

10-
from __future__ import division
11-
1210
import unittest
1311
from mock import patch
1412

@@ -18,7 +16,7 @@
1816
from .message_helper import ComparingMessagesTestCase
1917

2018

21-
class SerialDummy(object):
19+
class SerialDummy:
2220
"""
2321
Dummy to mock the serial communication
2422
"""

test/simplecyclic_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
This module tests cyclic send tasks.
66
"""
77

8-
from __future__ import absolute_import
9-
108
from time import sleep
119
import unittest
1210
import gc

test/test_detect_available_configs.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@
66
:meth:`can.BusABC.detect_available_configs`.
77
"""
88

9-
from __future__ import absolute_import
10-
119
import sys
1210
import unittest
13-
if sys.version_info.major > 2:
14-
basestring = str
1511

1612
from can import detect_available_configs
1713

@@ -33,7 +29,7 @@ def test_general_values(self):
3329
for config in configs:
3430
self.assertIn('interface', config)
3531
self.assertIn('channel', config)
36-
self.assertIsInstance(config['interface'], basestring)
32+
self.assertIsInstance(config['interface'], str)
3733

3834
def test_content_virtual(self):
3935
configs = detect_available_configs(interfaces='virtual')

test/test_kvaser.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
import time
99
import logging
1010
import unittest
11-
try:
12-
from unittest.mock import Mock, patch
13-
except ImportError:
14-
from mock import patch, Mock
11+
from unittest.mock import Mock, patch
1512

1613
import pytest
1714

0 commit comments

Comments
 (0)