8000 Make tests pass on Python 2.6 · sonlinux/client_python@225a95a · GitHub
[go: up one dir, main page]

Skip to content

Commit 225a95a

Browse files
committed
Make tests pass on Python 2.6
1 parent ab5b401 commit 225a95a

File tree

6 files changed

+29
-8
lines changed

6 files changed

+29
-8
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ language: python
77

88
matrix:
99
include:
10+
- python: "2.6"
11+
env: TOXENV=py26
1012
- python: "2.7"
1113
env: TOXENV=py27
1214
- python: "2.7"

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"Intended Audience :: System Administrators",
2424
"Programming Language :: Python",
2525
"Programming Language :: Python :: 2",
26+
"Programming Language :: Python :: 2.6",
2627
"Programming Language :: Python :: 2.7",
2728
"Programming Language :: Python :: 3",
2829
"Programming Language :: Python :: 3.4",

tests/test_exposition.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
from __future__ import unicode_literals
2-
import os
2+
33
import sys
44
import threading
5-
import time
6-
import unittest
75

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

912
from prometheus_client import Gauge, Counter, Summary, Histogram, Metric
1013
from prometheus_client import CollectorRegistry, generate_latest
@@ -39,6 +42,7 @@ def test_summary(self):
3942
s.labels('c', 'd').observe(17)
4043
self.assertEqual(b'# HELP ss A summary\n# TYPE ss summary\nss_count{a="c",b="d"} 1.0\nss_sum{a="c",b="d"} 17.0\n', generate_latest(self.registry))
4144

45+
@unittest.skipIf(sys.version_info < (2, 7), "Test requires Python 2.7+.")
4246
def test_histogram(self):
4347
s = Histogram('hh', 'A histogram', registry=self.registry)
4448
s.observe(0.05)

tests/test_parser.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
from __future__ import unicode_literals
22

3-
import unittest
3+
import sys
4+
5+
if sys.version_info < (2, 7):
6+
# We need the skip decorators from unittest2 on Python 2.6.
7+
import unittest2 as unittest
8+
else:
9+
import unittest
410

511
from prometheus_client.core import *
612
from prometheus_client.exposition import *
@@ -36,7 +42,7 @@ def test_summary_quantiles(self):
3642
a_count 1
3743
a_sum 2
3844
a{quantile="0.5"} 0.7
39-
""")
45+
""")
4046
# The Python client doesn't support quantiles, but we
4147
# still need to be able to parse them.
4248
metric_family = SummaryMetricFamily("a", "help", count_value=1, sum_value=2)
@@ -131,6 +137,7 @@ def test_escaping(self):
131137
metric_family.add_metric(["b\\a\\z"], 2)
132138
self.assertEqual([metric_family], list(families))
133139

140+
@unittest.skipIf(sys.version_info < (2, 7), "Test requires Python 2.7+.")
134141
def test_roundtrip(self):
135142
text = """# HELP go_gc_duration_seconds A summary of the GC invocation durations.
136143
# TYPE go_gc_duration_seconds summary

tests/test_twisted.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
from __future__ import absolute_import, unicode_literals
22

3-
from unittest import skipUnless
3+
import sys
4+
5+
if sys.version_info < (2, 7):
6+
from unittest2 import skipUnless
7+
else:
8+
from unittest import skipUnless
49

510
from prometheus_client import Counter
611
from prometheus_client import CollectorRegistry, generate_latest

tox.ini

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = coverage-clean,py27,py34,py35,pypy,{py27,py35}-nooptionals,coverage-report
2+
envlist = coverage-clean,py26,py27,py34,py35,pypy,{py27,py35}-nooptionals,coverage-report
33

44

55
[base]
@@ -10,7 +10,9 @@ deps =
1010
[testenv]
1111
deps =
1212
{[base]deps}
13-
twisted
13+
py26: unittest2
14+
; Twisted does not support Python 2.6.
15+
{py27,py34,py35,pypy}: twisted
1416
commands = coverage run --parallel -m pytest {posargs}
1517

1618

0 commit comments

Comments
 (0)
0