Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit c50f4b0

Browse files
authored
Quick fix for 3.x deprecation warnings (#344)
1 parent 9c07ae4 commit c50f4b0

2 files changed

Lines changed: 34 additions & 28 deletions

File tree

tests/unit/metrics/export/test_summary.py

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from six import assertRaisesRegex
1516
import unittest
17+
1618
from opencensus.metrics.export import summary as summary_module
1719

1820

1921
class TestSummary(unittest.TestCase):
20-
2122
def setUp(self):
2223
value_at_percentile = [summary_module.ValueAtPercentile(99.5, 10.2)]
2324
self.snapshot = summary_module.Snapshot(10, 87.07, value_at_percentile)
@@ -26,46 +27,50 @@ def test_constructor(self):
2627
summary = summary_module.Summary(10, 6.6, self.snapshot)
2728

2829
self.assertIsNotNone(summary)
29-
self.assertEquals(summary.count, 10)
30-
self.assertEquals(summary.sum_data, 6.6)
30+
self.assertEqual(summary.count, 10)
31+
self.assertEqual(summary.sum_data, 6.6)
3132
self.assertIsNotNone(summary.snapshot)
3233
self.assertIsInstance(summary.snapshot, summary_module.Snapshot)
3334

3435
def test_constructor_with_negative_count(self):
35-
with self.assertRaisesRegexp(ValueError, 'count must be non-negative'):
36+
with assertRaisesRegex(self, ValueError, 'count must be non-negative'):
3637
summary_module.Summary(-10, 87.07, self.snapshot)
3738

3839
def test_constructor_with_negative_sum_data(self):
39-
with self.assertRaisesRegexp(ValueError, 'sum_data must be non-negative'):
40+
with assertRaisesRegex(self, ValueError,
41+
'sum_data must be non-negative'):
4042
summary_module.Summary(10, -87.07, self.snapshot)
4143

4244
def test_constructor_with_zero_count_and_sum_data(self):
43-
with self.assertRaisesRegexp(ValueError, 'sum_data must be 0 if count is 0'):
45+
with assertRaisesRegex(self, ValueError,
46+
'sum_data must be 0 if count is 0'):
4447
summary_module.Summary(0, 87.07, self.snapshot)
4548

4649
def test_constructor_with_none_snapshot(self):
47-
with self.assertRaisesRegexp(ValueError, 'snapshot must not be none'):
50+
with assertRaisesRegex(self, ValueError, 'snapshot must not be none'):
4851
summary_module.Summary(10, 87.07, None)
4952

5053

5154
class TestSnapshot(unittest.TestCase):
52-
5355
def setUp(self):
54-
self.value_at_percentile = [summary_module.ValueAtPercentile(99.5, 10.2)]
56+
self.value_at_percentile = [
57+
summary_module.ValueAtPercentile(99.5, 10.2)
58+
]
5559

5660
# Invalid value_at_percentile
57-
self.value_at_percentile1 = summary_module.ValueAtPercentile(99.5, 10.2)
61+
self.value_at_percentile1 = summary_module.ValueAtPercentile(
62+
99.5, 10.2)
5863

5964
def test_constructor(self):
6065
snapshot = summary_module.Snapshot(10, 87.07, self.value_at_percentile)
6166

6267
self.assertIsNotNone(snapshot)
63-
self.assertEquals(snapshot.count, 10)
64-
self.assertEquals(snapshot.sum_data, 87.07)
68+
self.assertEqual(snapshot.count, 10)
69+
self.assertEqual(snapshot.sum_data, 87.07)
6570
self.assertIsNotNone(snapshot.value_at_percentiles)
66-
self.assertEquals(len(snapshot.value_at_percentiles), 1)
67-
self.assertEquals(snapshot.value_at_percentiles[0].percentile, 99.5)
68-
self.assertEquals(snapshot.value_at_percentiles[0].value, 10.2)
71+
self.assertEqual(len(snapshot.value_at_percentiles), 1)
72+
self.assertEqual(snapshot.value_at_percentiles[0].percentile, 99.5)
73+
self.assertEqual(snapshot.value_at_percentiles[0].value, 10.2)
6974

7075
def test_constructor_invalid_value_at_percentile(self):
7176
with self.assertRaises(ValueError):
@@ -76,46 +81,48 @@ def test_constructor_empty_value_at_percentile(self):
7681

7782
self.assertIsNotNone(snapshot)
7883
self.assertIsNotNone(snapshot.value_at_percentiles)
79-
self.assertEquals(len(snapshot.value_at_percentiles), 0)
84+
self.assertEqual(len(snapshot.value_at_percentiles), 0)
8085

8186
def test_constructor_with_negative_count(self):
82-
with self.assertRaisesRegexp(ValueError, 'count must be non-negative'):
87+
with assertRaisesRegex(self, ValueError, 'count must be non-negative'):
8388
summary_module.Snapshot(-10, 87.07, self.value_at_percentile)
8489

8590
def test_constructor_with_negative_sum_data(self):
86-
with self.assertRaisesRegexp(ValueError, 'sum_data must be non-negative'):
91+
with assertRaisesRegex(self, ValueError,
92+
'sum_data must be non-negative'):
8793
summary_module.Snapshot(10, -87.07, self.value_at_percentile)
8894

8995
def test_constructor_with_zero_count(self):
90-
with self.assertRaisesRegexp(ValueError, 'sum_data must be 0 if count is 0'):
96+
with assertRaisesRegex(self, ValueError,
97+
'sum_data must be 0 if count is 0'):
9198
summary_module.Snapshot(0, 87.07, self.value_at_percentile)
9299

93100
def test_constructor_with_zero_count_and_sum_data(self):
94101
summary_module.Snapshot(0, 0, self.value_at_percentile)
95102

96103
def test_constructor_with_none_count_sum(self):
97-
snapshot = summary_module.Snapshot(None, None, self.value_at_percentile)
104+
snapshot = summary_module.Snapshot(None, None,
105+
self.value_at_percentile)
98106

99107
self.assertIsNotNone(snapshot)
100108
self.assertIsNone(snapshot.count)
101109
self.assertIsNone(snapshot.sum_data)
102110
self.assertIsNotNone(snapshot.value_at_percentiles)
103-
self.assertEquals(len(snapshot.value_at_percentiles), 1)
111+
self.assertEqual(len(snapshot.value_at_percentiles), 1)
104112

105113

106114
class TestValueAtPercentile(unittest.TestCase):
107-
108115
def test_constructor(self):
109116
value_at_percentile = summary_module.ValueAtPercentile(99.5, 10.2)
110117

111118
self.assertIsNotNone(value_at_percentile)
112-
self.assertEquals(value_at_percentile.value, 10.2)
113-
self.assertEquals(value_at_percentile.percentile, 99.5)
119+
self.assertEqual(value_at_percentile.value, 10.2)
120+
self.assertEqual(value_at_percentile.percentile, 99.5)
114121

115122
def test_constructor_invalid_percentile(self):
116123
with self.assertRaises(ValueError):
117124
summary_module.ValueAtPercentile(100.1, 10.2)
118125

119126
def test_constructor_invalid_value(self):
120-
with self.assertRaisesRegexp(ValueError, 'value must be non-negative'):
127+
with assertRaisesRegex(self, ValueError, 'value must be non-negative'):
121128
summary_module.ValueAtPercentile(99.5, -10.2)

tests/unit/metrics/test_label_value.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020

2121
class TestLabelValue(unittest.TestCase):
22-
2322
def test_constructor(self):
2423
value = 'value1'
2524
label_value = label_value_module.LabelValue(value)
@@ -38,11 +37,11 @@ def test_constructor_Empty(self):
3837
label_value = label_value_module.LabelValue(value)
3938

4039
self.assertIsNotNone(label_value)
41-
self.assertEquals(label_value.value, '')
40+
self.assertEqual(label_value.value, '')
4241

4342
def test_constructor_WithNonAsciiChars(self):
4443
value = '值'
4544
label_value = label_value_module.LabelValue(value)
4645

4746
self.assertIsNotNone(label_value)
48-
self.assertEquals(label_value.value, value)
47+
self.assertEqual(label_value.value, value)

0 commit comments

Comments
 (0)