Skip to content

Commit

Permalink
Remove redundant Python 2.6 code
Browse files Browse the repository at this point in the history
Signed-off-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
  • Loading branch information
hugovk committed Oct 13, 2021
1 parent 9e67ea6 commit a9800c4
Show file tree
Hide file tree
Showing 11 changed files with 11 additions and 74 deletions.
3 changes: 1 addition & 2 deletions prometheus_client/exposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
CONTENT_TYPE_LATEST = str('text/plain; version=0.0.4; charset=utf-8')
"""Content type of the latest text format"""
PYTHON27_OR_OLDER = sys.version_info < (3, )
PYTHON26_OR_OLDER = sys.version_info < (2, 7)
PYTHON376_OR_NEWER = sys.version_info > (3, 7, 5)


Expand Down Expand Up @@ -445,7 +444,7 @@ def _use_gateway(method, gateway, job, registry, grouping_key, timeout, handler)
gateway_url = urlparse(gateway)
# See https://bugs.python.org/issue27657 for details on urlparse in py>=3.7.6.
if not gateway_url.scheme or (
(PYTHON376_OR_NEWER or PYTHON26_OR_OLDER)
PYTHON376_OR_NEWER
and gateway_url.scheme not in ['http', 'https']
):
gateway = 'http://{0}'.format(gateway)
Expand Down
8 changes: 2 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
from os import path
import sys

from setuptools import setup

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


setup(
Expand Down
9 changes: 1 addition & 8 deletions tests/openmetrics/test_exposition.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import unicode_literals

import sys
import time
import unittest

from prometheus_client import (
CollectorRegistry, Counter, Enum, Gauge, Histogram, Info, Metric, Summary,
Expand All @@ -11,12 +11,6 @@
)
from prometheus_client.openmetrics.exposition import generate_latest

if sys.version_info < (2, 7):
# We need the skip decorators from unittest2 on Python 2.6.
import unittest2 as unittest
else:
import unittest


class TestGenerateText(unittest.TestCase):
def setUp(self):
Expand Down Expand Up @@ -70,7 +64,6 @@ def test_summary(self):
# EOF
""", generate_latest(self.registry))

@unittest.skipIf(sys.version_info < (2, 7), "Test requires Python 2.7+.")
def test_histogram(self):
s = Histogram('hh', 'A histogram', registry=self.registry)
s.observe(0.05)
Expand Down
8 changes: 1 addition & 7 deletions tests/openmetrics/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import math
import sys
import unittest

from prometheus_client.core import (
CollectorRegistry, CounterMetricFamily, Exemplar,
Expand All @@ -12,12 +13,6 @@
from prometheus_client.openmetrics.exposition import generate_latest
from prometheus_client.openmetrics.parser import text_string_to_metric_families

if sys.version_info < (2, 7):
# We need the skip decorators from unittest2 on Python 2.6.
import unittest2 as unittest
else:
import unittest


class TestParse(unittest.TestCase):

Expand Down Expand Up @@ -549,7 +544,6 @@ def test_fallback_to_state_machine_label_parsing(self):
mock2.assert_not_called()
mock3.assert_called_once_with('1')

@unittest.skipIf(sys.version_info < (2, 7), "Test requires Python 2.7+.")
def test_roundtrip(self):
text = """# HELP go_gc_duration_seconds A summary of the GC invocation durations.
# TYPE go_gc_duration_seconds summary
Expand Down
6 changes: 1 addition & 5 deletions tests/test_asgi.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
from __future__ import absolute_import, unicode_literals

import sys
from unittest import TestCase
from unittest import skipUnless

from prometheus_client import CollectorRegistry, Counter
from prometheus_client.exposition import CONTENT_TYPE_LATEST

if sys.version_info < (2, 7):
from unittest2 import skipUnless
else:
from unittest import skipUnless

try:
# Python >3.5 only
Expand Down
8 changes: 1 addition & 7 deletions tests/test_exposition.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import unicode_literals

import sys
import threading
import time
import unittest

import pytest

Expand All @@ -17,11 +17,6 @@
passthrough_redirect_handler,
)

if sys.version_info < (2, 7):
# We need the skip decorators from unittest2 on Python 2.6.
import unittest2 as unittest
else:
import unittest

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

@unittest.skipIf(sys.version_info < (2, 7), "Test requires Python 2.7+.")
def test_histogram(self):
s = Histogram('hh', 'A histogram', registry=self.registry)
s.observe(0.05)
Expand Down
7 changes: 1 addition & 6 deletions tests/test_gc_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
import gc
import platform
import sys

if sys.version_info < (2, 7):
# We need the skip decorators from unittest2 on Python 2.6.
import unittest2 as unittest
else:
import unittest
import unittest

from prometheus_client import CollectorRegistry, GCCollector

Expand Down
10 changes: 1 addition & 9 deletions tests/test_multiprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import glob
import os
import shutil
import sys
import tempfile
import warnings
import unittest

from prometheus_client import mmap_dict, values
from prometheus_client.core import (
Expand All @@ -18,12 +18,6 @@
get_value_class, MultiProcessValue, MutexValue,
)

if sys.version_info < (2, 7):
# We need the skip decorators from unittest2 on Python 2.6.
import unittest2 as unittest
else:
import unittest


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

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

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

@unittest.skipIf(sys.version_info < (2, 7), "Test requires Python 2.7+.")
def test_merge_no_accumulate(self):
pid = 0
values.ValueClass = MultiProcessValue(lambda: pid)
Expand Down
9 changes: 1 addition & 8 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import unicode_literals

import math
import sys
import unittest

from prometheus_client.core import (
CollectorRegistry, CounterMetricFamily, GaugeMetricFamily,
Expand All @@ -10,12 +10,6 @@
from prometheus_client.exposition import generate_latest
from prometheus_client.parser import text_string_to_metric_families

if sys.version_info < (2, 7):
# We need the skip decorators from unittest2 on Python 2.6.
import unittest2 as unittest
else:
import unittest


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

@unittest.skipIf(sys.version_info < (2, 7), "Test requires Python 2.7+.")
def test_roundtrip(self):
text = """# HELP go_gc_duration_seconds A summary of the GC invocation durations.
# TYPE go_gc_duration_seconds summary
Expand Down
6 changes: 1 addition & 5 deletions tests/test_twisted.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
from __future__ import absolute_import, unicode_literals

import sys
from unittest import skipUnless

from prometheus_client import CollectorRegistry, Counter, generate_latest

if sys.version_info < (2, 7):
from unittest2 import skipUnless
else:
from unittest import skipUnless

try:
from twisted.internet import reactor
Expand Down
11 changes: 0 additions & 11 deletions tests/test_wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,6 @@ def capture(self, status, header):
self.captured_status = status
self.captured_headers = header

def assertIn(self, item, iterable):
try:
super().assertIn(item, iterable)
except: # Python < 2.7
self.assertTrue(
item in iterable,
msg="{item} not found in {iterable}".format(
item=item, iterable=iterable
)
)

def validate_metrics(self, metric_name, help_text, increments):
"""
WSGI app serves the metrics from the provided registry.
Expand Down

0 comments on commit a9800c4

Please sign in to comment.