From b05300522a3e316a5c4ea055c3bfc923895171ee Mon Sep 17 00:00:00 2001 From: Jeremy Muhlich Date: Wed, 21 Feb 2024 17:26:00 -0500 Subject: [PATCH] Add python 3.12 to CI matrix (#586) * Use raw strings for strings with incidental backslashes * Correct spelling of now-renamed assert_raises_regex * Work around Python 3.12 OrderedDict repr in doctest: Python 3.12 changed the OrderedDict repr to emit a dict literal as the constructor argument instead of a list of tuples. We have one doctest that returns an OrderedDict, failing on 3.12 without this workaround. This change adds a temporary monkeypatch to collections.OrderedDict in the nose module-level fixture, but I don't like it. --- .github/workflows/ci.yml | 2 +- pysb/bng.py | 2 +- pysb/export/stochkit.py | 6 +++--- pysb/importers/bngl.py | 2 +- pysb/kappa.py | 2 +- pysb/pattern.py | 24 ++++++++++++++++++++++++ pysb/tests/test_bng.py | 4 ++-- pysb/tests/test_importers.py | 4 ++-- 8 files changed, 35 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dec1f2a0d..ab1b4fc27 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: os: ["ubuntu-latest", "macos-latest", "windows-latest"] - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] defaults: run: shell: bash -l {0} diff --git a/pysb/bng.py b/pysb/bng.py index ba3b49254..2cf116a2d 100644 --- a/pysb/bng.py +++ b/pysb/bng.py @@ -850,7 +850,7 @@ def _parse_reaction(model, line, reaction_cache): rule_list = rule_list.split(',') # BNG lists all rules that generate a rxn # Support new (BNG 2.2.6-stable or greater) and old BNG naming convention # for reverse rules - rule_name, is_reverse = zip(*[re.subn('^_reverse_|\(reverse\)$', '', r) + rule_name, is_reverse = zip(*[re.subn(r'^_reverse_|\(reverse\)$', '', r) for r in rule_list]) is_reverse = tuple(bool(i) for i in is_reverse) r_names = ['__s%d' % r for r in reactants] diff --git a/pysb/export/stochkit.py b/pysb/export/stochkit.py index 7f4f2f731..1cf1fd42b 100644 --- a/pysb/export/stochkit.py +++ b/pysb/export/stochkit.py @@ -225,7 +225,7 @@ def export(self, initials=None, param_values=None): # Reactions reacs = etree.Element('ReactionsList') - pattern = re.compile("(__s\d+)\*\*(\d+)") + pattern = re.compile(r"(__s\d+)\*\*(\d+)") for rxn_id, rxn in enumerate(self.model.reactions): rxn_name = 'Rxn%d' % rxn_id rxn_desc = 'Rules: %s' % str(rxn["rule"]) @@ -325,6 +325,6 @@ def export(self, initials=None, param_values=None): doc = etree.tostring(document) xmldoc = xml.dom.minidom.parseString(doc) uglyXml = xmldoc.toprettyxml(indent=' ') - text_re = re.compile(">\n\s+([^<>\s].*?)\n\s+\g<1>\n\s+([^<>\s].*?)\n\s+\g<1>> A(), kf) - assert_raises_regexp( + assert_raises_regex( BngInterfaceError, 'Molecule created in reaction rule: Component\(s\) a missing from molecule A\(\)', generate_equations, diff --git a/pysb/tests/test_importers.py b/pysb/tests/test_importers.py index 8a8da6bfd..e5f5b5c30 100644 --- a/pysb/tests/test_importers.py +++ b/pysb/tests/test_importers.py @@ -4,7 +4,7 @@ from pysb.importers.bngl import model_from_bngl, BnglImportError from pysb.importers.sbml import model_from_sbml, model_from_biomodels import numpy -from nose.tools import assert_raises_regexp, raises +from nose.tools import assert_raises_regex, raises import warnings import mock import tempfile @@ -203,7 +203,7 @@ def test_bngl_import_expected_errors(): for filename, errmsg in expected_errors.items(): full_filename = _bngl_location(filename) - yield (assert_raises_regexp, + yield (assert_raises_regex, BnglImportError, errmsg, bngl_import_compare_simulations,