Skip to content

Commit

Permalink
Merge pull request graphite-project#951 from deniszh/py3.12-support
Browse files Browse the repository at this point in the history
Py3.12 support
  • Loading branch information
deniszh authored Sep 17, 2023
2 parents 798bf76 + 5b82e16 commit 66ebee1
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 45 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/tests-amd64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ jobs:
- name: "Python 3.11"
python-version: '3.11'
toxenv: 'py311'
# - name: "Python 3.12"
# python-version: '3.12'
# toxenv: 'py312'
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
Expand Down
12 changes: 0 additions & 12 deletions lib/carbon/routers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import imp
from carbon.hashing import ConsistentHashRing, carbonHash
from carbon.util import PluginRegistrar
from six import with_metaclass
Expand Down Expand Up @@ -125,17 +124,6 @@ def getDestinations(self, metric):
def getKey(self, metric):
return metric

def setKeyFunction(self, func):
self.getKey = func

def setKeyFunctionFromModule(self, keyfunc_spec):
module_path, func_name = keyfunc_spec.rsplit(':', 1)
module_file = open(module_path, 'U')
description = ('.py', 'U', imp.PY_SOURCE)
module = imp.load_module('keyfunc_module', module_file, module_path, description)
keyfunc = getattr(module, func_name)
self.setKeyFunction(keyfunc)


class AggregatedConsistentHashingRouter(DatapointRouter):
plugin_name = 'aggregated-consistent-hashing'
Expand Down
2 changes: 1 addition & 1 deletion lib/carbon/tests/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ def test_write_to_logfile(self):

with open(path.join(tmpdir, 'creates.log')) as logfile:
read_line = logfile.readline()
self.assertRegexpMatches(read_line, '.*😀😀😀😀 test !!!!')
self.assertRegex(read_line, '.*😀😀😀😀 test !!!!')
8 changes: 4 additions & 4 deletions lib/carbon/tests/test_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_build(self):

expected_plugins = sorted(expected_plugins)
plugins = sorted(MetricReceiver.plugins.keys())
self.assertEquals(expected_plugins, plugins)
self.assertEqual(expected_plugins, plugins)

class _FakeService(object):
def addService(_, __):
Expand Down Expand Up @@ -339,7 +339,7 @@ def test_cache_query_response_has_datapoints(self):

def test_cache_query_returns_empty_if_no_match(self):
self.send_request('cache-query', metric='carbon.foo')
self.assertEquals({'datapoints': []}, self.response)
self.assertEqual({'datapoints': []}, self.response)

def test_cache_query_returns_cached_datapoints_if_matches(self):
self.cache.store('carbon.foo', (600, 1.0))
Expand All @@ -356,12 +356,12 @@ def test_cache_bulk_query_response_has_datapointsByMetric(self):

def test_cache_bulk_query_response_returns_empty_if_no_match(self):
self.send_request('cache-query-bulk', metrics=[])
self.assertEquals({'datapointsByMetric': {}}, self.response)
self.assertEqual({'datapointsByMetric': {}}, self.response)

def test_cache_bulk_query_response(self):
self.cache.store('carbon.foo', (600, 1.0))
self.cache.store('carbon.bar', (600, 2.0))

expected_response = {'carbon.foo': [(600, 1.0)], 'carbon.bar': [(600, 2.0)]}
self.send_request('cache-query-bulk', metrics=['carbon.foo', 'carbon.bar'])
self.assertEquals({'datapointsByMetric': expected_response}, self.response)
self.assertEqual({'datapointsByMetric': expected_response}, self.response)
10 changes: 6 additions & 4 deletions lib/carbon/tests/test_routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def testBasic(self):
router = routers.RelayRulesRouter(createSettings())
for destination in DESTINATIONS:
router.addDestination(parseDestination(destination))
self.assertEquals(len(list(router.getDestinations('foo.bar'))), 1)
self.assertEqual(len(list(router.getDestinations('foo.bar'))), 1)


class TestOtherRouters(unittest.TestCase):
Expand All @@ -48,9 +48,11 @@ def testBasic(self):
continue

router = routers.DatapointRouter.plugins[plugin](settings)
self.assertEquals(len(list(router.getDestinations('foo.bar'))), 0)
self.assertEqual(len(list(router.getDestinations('foo.bar'))), 0)

for destination in DESTINATIONS:
router.addDestination(parseDestination(destination))
self.assertEquals(len(list(router.getDestinations('foo.bar'))),
settings['REPLICATION_FACTOR'])
self.assertEqual(
len(list(router.getDestinations('foo.bar'))),
settings['REPLICATION_FACTOR']
)
26 changes: 13 additions & 13 deletions lib/carbon/tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
# def test_loadAggregationSchemas_load_default_schema(self):
# from carbon.storage import loadAggregationSchemas, defaultAggregation
# schema_list = loadAggregationSchemas()
# self.assertEquals(len(schema_list), 1)
# self.assertEqual(len(schema_list), 1)
# schema = schema_list[0]
# self.assertEquals(schema, defaultAggregation)
# self.assertEqual(schema, defaultAggregation)

# def test_loadStorageSchemas_raise_CarbonConfigException(self):
# from carbon.storage import loadStorageSchemas
Expand Down Expand Up @@ -51,41 +51,41 @@ def tearDown(self):
def test_loadStorageSchemas_return_schemas(self):
from carbon.storage import loadStorageSchemas, PatternSchema, Archive
schema_list = loadStorageSchemas()
self.assertEquals(len(schema_list), 3)
self.assertEqual(len(schema_list), 3)
expected = [
PatternSchema('carbon', r'^carbon\.', [Archive.fromString('60:90d')]),
PatternSchema('default_1min_for_1day', '.*', [Archive.fromString('60s:1d')])
]
for schema, expected_schema in zip(schema_list[:-1], expected):
self.assertEquals(schema.name, expected_schema.name)
self.assertEquals(schema.pattern, expected_schema.pattern)
self.assertEqual(schema.name, expected_schema.name)
self.assertEqual(schema.pattern, expected_schema.pattern)
for (archive, expected_archive) in zip(schema.archives, expected_schema.archives):
self.assertEquals(archive.getTuple(), expected_archive.getTuple())
self.assertEqual(archive.getTuple(), expected_archive.getTuple())

def test_loadStorageSchemas_return_the_default_schema_last(self):
from carbon.storage import loadStorageSchemas, defaultSchema
schema_list = loadStorageSchemas()
last_schema = schema_list[-1]
self.assertEquals(last_schema.name, defaultSchema.name)
self.assertEquals(last_schema.archives, defaultSchema.archives)
self.assertEqual(last_schema.name, defaultSchema.name)
self.assertEqual(last_schema.archives, defaultSchema.archives)

def test_loadAggregationSchemas_return_schemas(self):
from carbon.storage import loadAggregationSchemas, PatternSchema
schema_list = loadAggregationSchemas()
self.assertEquals(len(schema_list), 5)
self.assertEqual(len(schema_list), 5)
expected = [
PatternSchema('min', r'\.min$', (0.1, 'min')),
PatternSchema('max', r'\.max$', (0.1, 'max')),
PatternSchema('sum', r'\.count$', (0, 'sum')),
PatternSchema('default_average', '.*', (0.5, 'average'))
]
for schema, expected_schema in zip(schema_list[:-1], expected):
self.assertEquals(schema.name, expected_schema.name)
self.assertEquals(schema.pattern, expected_schema.pattern)
self.assertEquals(schema.archives, expected_schema.archives)
self.assertEqual(schema.name, expected_schema.name)
self.assertEqual(schema.pattern, expected_schema.pattern)
self.assertEqual(schema.archives, expected_schema.archives)

def test_loadAggregationSchema_return_the_default_schema_last(self):
from carbon.storage import loadAggregationSchemas, defaultAggregation
schema_list = loadAggregationSchemas()
last_schema = schema_list[-1]
self.assertEquals(last_schema, defaultAggregation)
self.assertEqual(last_schema, defaultAggregation)
16 changes: 8 additions & 8 deletions lib/carbon/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def setTcpKeepAlive(self, value):
s.setsockopt(socket.SOL_TCP, socket.SO_KEEPALIVE, value)

enableTcpKeepAlive(_Transport(), True, None)
self.assertEquals(s.getsockopt(socket.SOL_TCP, socket.SO_KEEPALIVE), 1)
self.assertEqual(s.getsockopt(socket.SOL_TCP, socket.SO_KEEPALIVE), 1)

def test_sanitizing_name_as_tag_value(self):
test_cases = [
Expand Down Expand Up @@ -61,7 +61,7 @@ def test_sanitizing_name_as_tag_value(self):
)
else:
result = TaggedSeries.sanitize_name_as_tag_value(test_case['original'])
self.assertEquals(result, test_case['expected'])
self.assertEqual(result, test_case['expected'])

def test_validate_tag_key_and_value(self):
# assert that it raises exception when sanitized name is still not valid
Expand Down Expand Up @@ -114,10 +114,10 @@ def test_valid_dest_unbracketed(self):
]

actual = parseDestinations(dests)
self.assertEquals(len(expected), len(actual))
self.assertEqual(len(expected), len(actual))

for exp, act in zip(expected, actual):
self.assertEquals(exp, act)
self.assertEqual(exp, act)

def test_valid_dest_bracketed(self):
# Tests valid destinations in the bracketed form of <host>.
Expand All @@ -136,10 +136,10 @@ def test_valid_dest_bracketed(self):
]

actual = parseDestinations(dests)
self.assertEquals(len(expected), len(actual))
self.assertEqual(len(expected), len(actual))

for exp, act in zip(expected, actual):
self.assertEquals(exp, act)
self.assertEqual(exp, act)

def test_valid_dest_without_instance(self):
# Tests destinations without instance specified.
Expand All @@ -160,10 +160,10 @@ def test_valid_dest_without_instance(self):
]

actual = parseDestinations(dests)
self.assertEquals(len(expected), len(actual))
self.assertEqual(len(expected), len(actual))

for exp, act in zip(expected, actual):
self.assertEquals(exp, act)
self.assertEqual(exp, act)

def test_wrong_dest(self):
# Some cases of invalid input, e.g. invalid/missing port.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
with open('setup.cfg', 'r') as f:
orig_setup_cfg = f.read()
f.seek(0)
cf.readfp(f, 'setup.cfg')
cf.read_file(f, 'setup.cfg')

if os.environ.get('GRAPHITE_NO_PREFIX'):
cf.remove_section('install')
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
envlist =
py{37,38,39,310,311,py3}{,-pyhash},
py{37,38,39,310,311,312,py3}{,-pyhash},
lint,
benchmark

Expand Down

0 comments on commit 66ebee1

Please sign in to comment.