8000 Remove redundant Python 2.6 code · SnoopJ/client_python@a9800c4 · GitHub
[go: up one dir, main page]

Skip to content

Commit a9800c4

Browse files
committed
Remove redundant Python 2.6 code
Signed-off-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
1 parent 9e67ea6 commit a9800c4

11 files changed

+11
-74
lines changed

prometheus_client/exposition.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
CONTENT_TYPE_LATEST = str('text/plain; version=0.0.4; charset=utf-8')
3535
"""Content type of the latest text format"""
3636
PYTHON27_OR_OLDER = sys.version_info < (3, )
37-
PYTHON26_OR_OLDER = sys.version_info < (2, 7)
3837
PYTHON376_OR_NEWER = sys.version_info > (3, 7, 5)
3938

4039

@@ -445,7 +444,7 @@ def _use_gateway(method, gateway, job, registry, grouping_key, timeout, handler)
445444
gateway_url = urlparse(gateway)
446445
# See https://bugs.python.org/issue27657 for details on urlparse in py>=3.7.6.
447446
if not gateway_url.scheme or (
448-
(PYTHON376_OR_NEWER or PYTHON26_OR_OLDER)
447+
PYTHON376_OR_NEWER
449448
and gateway_url.scheme not in ['http', 'https']
450449
):
451450
gateway = 'http://{0}'.format(gateway)

setup.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
from os import path
2-
import sys
32

43
from setuptools import setup
54

6-
if sys.version_info >= (2, 7):
7-
with open(path.join(path.abspath(path.dirname(__file__)), 'README.md')) as f:
8-
long_description = f.read()
9-
else: # Assuming we don't run setup in order to publish under python 2.6
10-
long_description = "NA"
5+
with open(path.join(path.abspath(path.dirname(__file__)), 'README.md')) as f:
6+
long_description = f.read()
117

128

139
setup(

tests/openmetrics/test_exposition.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import unicode_literals
22

3-
import sys
43
import time
4+
import unittest
55

66
from prometheus_client import (
77
CollectorRegistry, Counter, Enum, Gauge, Histogram, Info, Metric, Summary,
@@ -11,12 +11,6 @@
1111
)
1212
from prometheus_client.openmetrics.exposition import generate_latest
1313

14-
if sys.version_info < (2, 7):
15-
# We need the skip decorators from unittest2 on Python 2.6.
16-
import unittest2 as unittest
17-
else:
18-
import unittest
19-
2014

2115
class TestGenerateText(unittest.TestCase):
2216
def setUp(self):
@@ -70,7 +64,6 @@ def test_summary(self):
7064
# EOF
7165
""", generate_latest(self.registry))
7266

73-
@unittest.skipIf(sys.version_info < (2, 7), "Test requires Python 2.7+.")
7467
def test_histogram(self):
7568
s = Histogram('hh', 'A histogram', registry=self.registry)
7669
s.observe(0.05)

tests/openmetrics/test_parser.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import math
44
import sys
5+
import unittest
56

67
from prometheus_client.core import (
78
CollectorRegistry, CounterMetricFamily, Exemplar,
@@ -12,12 +13,6 @@
1213
from prometheus_client.openmetrics.exposition import generate_latest
1314
from prometheus_client.openmetrics.parser import text_string_to_metric_families
1415

15-
if sys.version_info < (2, 7):
16-
# We need the skip decorators from unittest2 on Python 2.6.
17-
import unittest2 as unittest
18-
else:
19-
import unittest
20-
2116

2217
class TestParse(unittest.TestCase):
2318

@@ -549,7 +544,6 @@ def test_fallback_to_state_machine_label_parsing(self):
549544
mock2.assert_not_called()
550545
mock3.assert_called_once_with('1')
551546

552-
@unittest.skipIf(sys.version_info < (2, 7), "Test requires Python 2.7+.")
553547
def test_roundtrip(self):
554548
text = """# HELP go_gc_duration_seconds A summary of the GC invocation durations.
555549
# TYPE go_gc_duration_seconds summary

tests/test_asgi.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
from __future__ import absolute_import, unicode_literals
22

3-
import sys
43
from unittest import TestCase
4+
from unittest import skipUnless
55

66
from prometheus_client import CollectorRegistry, Counter
77
from prometheus_client.exposition import CONTENT_TYPE_LATEST
88

9-
if sys.version_info < (2, 7):
10-
from unittest2 import skipUnless
11-
else:
12-
from unittest import skipUnless
139

1410
try:
1511
# Python >3.5 only

tests/test_exposition.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from __future__ import unicode_literals
22

3-
import sys
43
import threading
54
import time
5+
import unittest
66

77
import pytest
88

@@ -17,11 +17,6 @@
1717
passthrough_redirect_handler,
1818
)
1919

20-
if sys.version_info < (2, 7):
21-
# We need the skip decorators from unittest2 on Python 2.6.
22-
import unittest2 as unittest
23-
else:
24-
import unittest
2520

2621
try:
2722
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
@@ -98,7 +93,6 @@ def test_summary(self):
9893
ss_created{a="c",b="d"} 123.456
9994
""", generate_latest(self.registry))
10095

101-
@unittest.skipIf(sys.version_info < (2, 7), "Test requires Python 2.7+.")
10296
def test_histogram(self):
10397
s = Histogram('hh', 'A histogram', registry=self.registry)
10498
s.observe(0.05)

tests/test_gc_collector.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
import gc
44
import platform
55
import sys
6-
7-
if sys.version_info < (2, 7):
8-
# We need the skip decorators from unittest2 on Python 2.6.
9-
import unittest2 as unittest
10-
else:
11-
import unittest
6+
import unittest
127

138
from prometheus_client import CollectorRegistry, GCCollector
149

tests/test_multiprocess.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import glob
44
import os
55
import shutil
6-
import sys
76
import tempfile
87
import warnings
8+
import unittest
99

1010
from prometheus_client import mmap_dict, values
1111
from prometheus_client.core import (
@@ -18,12 +18,6 @@
1818
get_value_class, MultiProcessValue, MutexValue,
1919
)
2020

21-
if sys.version_info < (2, 7):
22-
# We need the skip decorators from unittest2 on Python 2.6.
23-
import unittest2 as unittest
24-
else:
25-
import unittest
26-
2721

2822
class TestMultiProcessDeprecation(unittest.TestCase):
2923
def setUp(self):
@@ -196,7 +190,6 @@ def files():
196190
c3 = Counter('c3', 'c3', registry=None)
197191
self.assertEqual(files(), ['counter_0.db', 'counter_1.db'])
198192

199-
@unittest.skipIf(sys.version_info < (2, 7), "Test requires Python 2.7+.")
200193
def test_collect(self):
201194
pid = 0
202195
values.ValueClass = MultiProcessValue(lambda: pid)
@@ -257,7 +250,6 @@ def add_label(key, value):
257250

258251
self.assertEqual(metrics['h'].samples, expected_histogram)
259252

260-
@unittest.skipIf(sys.version_info < (2, 7), "Test requires Python 2.7+.")
261253
def test_merge_no_accumulate(self):
262254
pid = 0
263255
values.ValueClass = MultiProcessValue(lambda: pid)

tests/test_parser.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import unicode_literals
22

33
import math
4-
import sys
4+
import unittest
55

66
from prometheus_client.core import (
77
CollectorRegistry, CounterMetricFamily, GaugeMetricFamily,
@@ -10,12 +10,6 @@
1010
from prometheus_client.exposition import generate_latest
1111
from prometheus_client.parser import text_string_to_metric_families
1212

13-
if sys.version_info < (2, 7):
14-
# We need the skip decorators from unittest2 on Python 2.6.
15-
import unittest2 as unittest
16-
else:
17-
import unittest
18-
1913

2014
class TestParse(unittest.TestCase):
2115
def assertEqualMetrics(self, first, second, msg=None):
@@ -289,7 +283,6 @@ def test_timestamps(self):
289283
b.add_metric([], 88, timestamp=1234566)
290284
self.assertEqualMetrics([a, b], list(families))
291285

292-
@unittest.skipIf(sys.version_info < (2, 7), "Test requires Python 2.7+.")
293286
def test_roundtrip(self):
294287
text = """# HELP go_gc_duration_seconds A summary of the GC invocation durations.
295288
# TYPE go_gc_duration_seconds summary

tests/test_twisted.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
from __future__ import absolute_import, unicode_literals
22

3-
import sys
3+
from unittest import skipUnless
44

55
from prometheus_client import CollectorRegistry, Counter, generate_latest
66

7-
if sys.version_info < (2, 7):
8-
from unittest2 import skipUnless
9-
else:
10-
from unittest import skipUnless
117

128
try:
139
from twisted.internet import reactor

tests/test_wsgi.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,6 @@ def capture(self, status, header):
2222
self.captured_status = status
2323
self.captured_headers = header
2424

25-
def assertIn(self, item, iterable):
26-
try:
27-
super().assertIn(item, iterable)
28-
except: # Python < 2.7
29-
self.assertTrue(
30-
item in iterable,
31-
msg="{item} not found in {iterable}".format(
32-
item=item, iterable=iterable
33-
)
34-
)
35-
3625
def validate_metrics(self, metric_name, help_text, increments):
3726
"""
3827
WSGI app serves the metrics from the provided registry.

0 commit comments

Comments
 (0)
0