Skip to content

Commit 10c7197

Browse files
committed
Remove py2 compatibility-related ifs
1 parent e451deb commit 10c7197

10 files changed

Lines changed: 14 additions & 48 deletions

File tree

patterns/creational/pool.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ def __del__(self):
5454

5555

5656
def main():
57-
try:
58-
import queue
59-
except ImportError: # python 2.x compatibility
60-
import Queue as queue
57+
import queue
6158

6259
def test_object(queue):
6360
pool = ObjectPool(queue, True)

requirements-dev.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@
33
pytest~=4.3.0
44
pytest-cov~=2.6.0
55
flake8~=3.7.0
6-
7-
mock~=2.0.0; python_version < "3.*"

tests/behavioral/test_observer.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
import unittest
4-
from patterns.behavioral.observer import Subject, Data, DecimalViewer, HexViewer
4+
from unittest.mock import patch
55

6-
try:
7-
from unittest.mock import patch
8-
except ImportError:
9-
from mock import patch
6+
from patterns.behavioral.observer import Subject, Data, DecimalViewer, HexViewer
107

118

129
class TestSubject(unittest.TestCase):

tests/behavioral/test_publish_subscribe.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
import unittest
4+
from unittest.mock import patch, call
45
from patterns.behavioral.publish_subscribe import Provider, Publisher, Subscriber
56

6-
try:
7-
from unittest.mock import patch, call
8-
except ImportError:
9-
from mock import patch, call
10-
117

128
class TestProvider(unittest.TestCase):
139
"""

tests/creational/test_abstract_factory.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
import unittest
4-
from patterns.creational.abstract_factory import PetShop, Dog
4+
from unittest.mock import patch
55

6-
try:
7-
from unittest.mock import patch
8-
except ImportError:
9-
from mock import patch
6+
from patterns.creational.abstract_factory import PetShop, Dog
107

118

129
class TestPetShop(unittest.TestCase):

tests/creational/test_pool.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
import unittest
4+
import queue
45

5-
try:
6-
import queue
7-
except ImportError: # python 2.x compatibility
8-
import Queue as queue
96
from patterns.creational.pool import ObjectPool
107

118

tests/structural/test_bridge.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
import unittest
4-
from patterns.structural.bridge import DrawingAPI1, DrawingAPI2, CircleShape
4+
from unittest.mock import patch
55

6-
try:
7-
from unittest.mock import patch
8-
except ImportError:
9-
from mock import patch
6+
from patterns.structural.bridge import DrawingAPI1, DrawingAPI2, CircleShape
107

118

129
class BridgeTest(unittest.TestCase):

tests/structural/test_proxy.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
import sys
44
from time import time
55
import unittest
6-
from patterns.structural.proxy import Proxy, NoTalkProxy
6+
from io import StringIO
77

8-
if sys.version_info[0] == 2:
9-
from StringIO import StringIO
10-
else:
11-
from io import StringIO
8+
from patterns.structural.proxy import Proxy, NoTalkProxy
129

1310

1411
class ProxyTest(unittest.TestCase):

tests/test_hsm.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
import unittest
4+
from unittest.mock import patch
5+
46
from patterns.other.hsm.hsm import (
57
HierachicalStateMachine,
68
UnsupportedMessageType,
@@ -11,11 +13,6 @@
1113
Suspect,
1214
)
1315

14-
try:
15-
from unittest.mock import patch
16-
except ImportError:
17-
from mock import patch
18-
1916

2017
class HsmMethodTest(unittest.TestCase):
2118
@classmethod

tests/test_outputs.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
try:
2-
from contextlib import redirect_stdout
3-
except:
4-
pass
5-
1+
from contextlib import redirect_stdout
62
import io
7-
import sys
83

94
import pytest
105

@@ -16,8 +11,6 @@
1611
from patterns.behavioral.state import OUTPUT as state_output
1712

1813

19-
@pytest.mark.skipif(sys.version_info < (3,4),
20-
reason="requires python3.4 or higher")
2114
@pytest.mark.parametrize("main,output", [
2215
(publish_subscribe_main, publish_subscribe_output),
2316
(specification_main, specification_output),

0 commit comments

Comments
 (0)