Skip to content

Commit 6cc4b91

Browse files
authored
[Track CI] Upgrade Workflow to use Python 3.11.2 & Pytest 7.2.2 (exercism#3382)
* Upgraded CI workflow to use Python 3.11.2 and Pytest 7.2.2 * Pinned Pylint version to ~=2.17.1 * Added tomli to test_exercises.py imports. * Adding in tomli for dependancies. * Need to use latest build of Black due to Python 3.11 and packaging problems with tomli * Regenerated test files for exercises failing CI. * Try removing tomli to see if it fixes CI for Py3.11 * And more version fishing for black, which is the culprit here. * Regeneraed test files with black 22.3.0, since black 23.3.0 is incompatible with Python 3.11 due to tomli conflicts. * Trying a different strategy. Using only 3.11 for the main container. * Must import tomllib, part of exteded standard lib not core. * Wrapped tomllib in a try-catch and aliased importing tomli. Updated requirements to only install tmli on 3.10 and below. * Forgot to update the imports in the generator. * Added paasio test changes here, since this changes the CI checker to use Python 3.11. * Trying a msg= approach.
1 parent c865759 commit 6cc4b91

File tree

6 files changed

+32
-22
lines changed

6 files changed

+32
-22
lines changed

.github/workflows/ci-workflow.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Set up Python
2020
uses: actions/setup-python@v4
2121
with:
22-
python-version: 3.10.6
22+
python-version: 3.11.2
2323

2424
- name: Download & Install dependencies
2525
run: |
@@ -53,7 +53,7 @@ jobs:
5353
needs: housekeeping
5454
strategy:
5555
matrix:
56-
python-version: [3.7, 3.8, 3.9, 3.10.6]
56+
python-version: [3.7, 3.8, 3.9, 3.10.6, 3.11.2]
5757
steps:
5858
- uses: actions/checkout@v3
5959

@@ -66,7 +66,7 @@ jobs:
6666
run: pip install dataclasses
6767

6868
- name: Install pytest
69-
run: pip install pytest~=7.1.2
69+
run: pip install pytest~=7.2.2
7070

7171
- name: Check exercises
7272
run: |

bin/data.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@
44
from itertools import chain
55
import json
66
from pathlib import Path
7-
import tomli
87
from typing import List, Any, Dict, Type
98

9+
# Tomli was subsumed into Python 3.11.x, but was renamed to to tomllib.
10+
# This avoids ci failures for Python < 3.11.2.
11+
try:
12+
import tomllib
13+
except ModuleNotFoundError:
14+
import tomli as tomllib
15+
16+
1017

1118
def _custom_dataclass_init(self, *args, **kwargs):
1219
# print(self.__class__.__name__, "__init__")
@@ -355,7 +362,7 @@ class TestsTOML:
355362
@classmethod
356363
def load(cls, toml_path: Path):
357364
with toml_path.open("rb") as f:
358-
data = tomli.load(f)
365+
data = tomllib.load(f)
359366
return cls({uuid: TestCaseTOML(uuid, *opts) for
360367
uuid, opts in
361368
data.items() if

bin/generate_tests.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,17 @@
3434
from itertools import repeat
3535
from string import punctuation, whitespace
3636
from subprocess import check_call
37-
import tomli
3837
from tempfile import NamedTemporaryFile
3938
from textwrap import wrap
4039
from typing import Any, Dict, List, NoReturn, Union
4140

41+
# Tomli was subsumed into Python 3.11.x, but was renamed to to tomllib.
42+
# This avoids ci failures for Python < 3.11.2.
43+
try:
44+
import tomllib
45+
except ModuleNotFoundError:
46+
import tomli as tomllib
47+
4248
from jinja2 import Environment, FileSystemLoader, TemplateNotFound, UndefinedError
4349
from dateutil.parser import parse
4450

exercises/practice/paasio/paasio_test.py

+8-12
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,13 @@ def test_meteredsocket_stats_read_only(self):
199199
self.assertEqual(282, socket.send_bytes)
200200
self.assertEqual(258, socket.recv_ops)
201201
self.assertEqual(259, socket.recv_bytes)
202-
with self.assertRaisesRegex(AttributeError, "can't set"):
202+
with self.assertRaises(AttributeError, msg="property 'send_ops' of 'MeteredSocket' object has no setter"):
203203
socket.send_ops = 0
204-
with self.assertRaisesRegex(AttributeError, "can't set"):
204+
with self.assertRaises(AttributeError, msg="property 'send_bytes' of 'MeteredSocket' object has no setter"):
205205
socket.send_bytes = 0
206-
with self.assertRaisesRegex(AttributeError, "can't set"):
206+
with self.assertRaises(AttributeError, msg="property 'recv_ops' of 'MeteredSocket' object has no setter"):
207207
socket.recv_ops = 0
208-
with self.assertRaisesRegex(AttributeError, "can't set"):
208+
with self.assertRaises(AttributeError, msg="property 'recv_bytes' of 'MeteredSocket' object has no setter"):
209209
socket.recv_bytes = 0
210210
self.assertEqual(278, socket.send_ops)
211211
self.assertEqual(282, socket.send_bytes)
@@ -426,19 +426,15 @@ def test_meteredfile_stats_read_only(self, super_mock):
426426
file.write(b"bytes")
427427
self.assertEqual(78, file.write_ops)
428428
self.assertEqual(82, file.write_bytes)
429-
with self.assertRaisesRegex(AttributeError, "can't set"):
429+
with self.assertRaises(AttributeError, msg="property 'write_ops' of 'MeteredFile' object has no setter"):
430430
file.write_ops = 0
431-
with self.assertRaisesRegex(AttributeError, "can't set"):
431+
with self.assertRaises(AttributeError, msg="property 'write_bytes' of 'MeteredFile' object has no setter"):
432432
file.write_bytes = 0
433-
with self.assertRaisesRegex(AttributeError, "can't set"):
433+
with self.assertRaises(AttributeError, msg="property 'read_ops' of 'MeteredFile' object has no setter"):
434434
file.read_ops = 0
435-
with self.assertRaisesRegex(AttributeError, "can't set"):
435+
with self.assertRaises(AttributeError, msg="property 'read_bytes' of 'MeteredFile' object has no setter"):
436436
file.read_bytes = 0
437437
self.assertEqual(78, file.write_ops)
438438
self.assertEqual(82, file.write_bytes)
439439
self.assertEqual(58, file.read_ops)
440440
self.assertEqual(59, file.read_bytes)
441-
442-
443-
if __name__ == "__main__":
444-
unittest.main()

requirements-generator.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
black==22.3.0
1+
black<=22.3.0
22
flake8~=5.0.4
33
Jinja2~=3.1.2
44
python-dateutil==2.8.1
55
markupsafe==2.0.1
6-
tomli~=2.0.1
6+
tomli>=1.1.0; python_full_version < '3.11.2'

requirements.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
astroid<=2.12.0
22
flake8~=5.0.4
3-
pylint~=2.14.5
3+
pylint~=2.17.1
4+
black<=22.3.0
45
yapf~=0.32.0
5-
tomli~=2.0.1
6+
tomli>=1.1.0; python_full_version < '3.11.2'

0 commit comments

Comments
 (0)