Skip to content

Commit 90e129d

Browse files
tests: convert all to pytest
1 parent d52edc3 commit 90e129d

18 files changed

+2315
-2330
lines changed

libsemigroups_pybind11/transf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# The full license is in the file LICENSE, distributed with this software.
88

99
# pylint: disable=no-name-in-module, invalid-name
10-
# pylint: disable=bad-option-value, consider-using-f-string
10+
# pylint: disable=bad-option-value, consider-using-f-string, duplicate-code
1111

1212
"""
1313
This package provides a the user-facing python part of libsemigroups_pybind11

tests/element.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
# pylint: disable=no-name-in-module, missing-function-docstring
3-
# pylint: disable=missing-class-docstring, invalid-name
42

53
# Copyright (c) 2021, J. D. Mitchell
64
#
@@ -12,15 +10,17 @@
1210
This module contains some tests for elements.
1311
"""
1412

13+
# pylint: disable=no-name-in-module, missing-function-docstring, invalid-name
1514

16-
def check_products(self, x):
15+
16+
def check_products(x):
1717
y = x.identity()
1818
z = x.identity()
1919
z.product_inplace(x, y, 0)
20-
self.assertEqual(z, x)
20+
assert z == x
2121
z.product_inplace(y, x, 0)
22-
self.assertEqual(z, x)
22+
assert z == x
2323
z.product_inplace(x, x, 0)
24-
self.assertEqual(z, x * x)
25-
self.assertEqual(x * x.identity(), x)
26-
self.assertEqual(x.identity() * x, x)
24+
assert z == x * x
25+
assert x * x.identity() == x
26+
assert x.identity() * x == x

tests/fpsemi_intf.py

Lines changed: 71 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
# pylint: disable=no-name-in-module, missing-function-docstring
3-
# pylint: disable=missing-class-docstring, invalid-name
42

53
# Copyright (c) 2021, J. D. Mitchell + Maria Tsalakou
64
#
@@ -13,93 +11,96 @@
1311
derived classes, i.e. KnuthBendix, FpSemigroup, etc.
1412
"""
1513

14+
# pylint: disable=no-name-in-module, missing-function-docstring, invalid-name
15+
1616
from datetime import timedelta
17+
import pytest
1718
from runner import check_runner
1819
from libsemigroups_pybind11 import ReportGuard, FroidurePin, Transf
1920

2021

21-
def check_validation(self, t):
22+
def check_validation(t):
2223
ReportGuard(False)
2324
x = t()
2425
x.set_alphabet("ab")
2526

26-
with self.assertRaises(RuntimeError):
27+
with pytest.raises(RuntimeError):
2728
x.validate_letter("c")
2829
try:
2930
x.validate_letter("a")
3031
except RuntimeError as e:
31-
self.fail(
32+
pytest.fail(
3233
"unexpected exception raised for FpSemigroupInterface::validate_letter: "
3334
+ e
3435
)
3536

36-
with self.assertRaises(RuntimeError):
37+
with pytest.raises(RuntimeError):
3738
x.validate_letter(3)
3839
try:
3940
x.validate_letter(0)
4041
except RuntimeError as e:
41-
self.fail(
42+
pytest.fail(
4243
"unexpected exception raised for FpSemigroupInterface::validate_letter: "
4344
+ e
4445
)
45-
with self.assertRaises(RuntimeError):
46+
with pytest.raises(RuntimeError):
4647
x.validate_word("abc")
4748
try:
4849
x.validate_word("abab")
4950
except RuntimeError as e:
50-
self.fail(
51+
pytest.fail(
5152
"unexpected exception raised for FpSemigroupInterface::validate_letter: "
5253
+ e
5354
)
5455

55-
with self.assertRaises(RuntimeError):
56+
with pytest.raises(RuntimeError):
5657
x.validate_word([0, 1, 2])
5758

5859
try:
5960
x.validate_word([0, 1, 0, 1])
6061
except RuntimeError as e:
61-
self.fail(
62+
pytest.fail(
6263
"unexpected exception raised for FpSemigroupInterface::validate_letter: "
6364
+ e
6465
)
6566

6667

67-
def check_converters(self, t):
68+
def check_converters(t):
6869
ReportGuard(False)
6970
x = t()
7071
x.set_alphabet("ba")
71-
self.assertEqual(x.char_to_uint("a"), 1)
72-
self.assertEqual(x.char_to_uint("b"), 0)
72+
assert x.char_to_uint("a") == 1
73+
assert x.char_to_uint("b") == 0
7374

74-
self.assertEqual(x.string_to_word("ab"), [1, 0])
75-
self.assertEqual(x.string_to_word("aaaaaa"), [1] * 6)
76-
with self.assertRaises(RuntimeError):
75+
assert x.string_to_word("ab") == [1, 0]
76+
assert x.string_to_word("aaaaaa") == [1] * 6
77+
with pytest.raises(RuntimeError):
7778
x.string_to_word("c")
7879

79-
self.assertEqual(x.uint_to_char(0), "b")
80-
self.assertEqual(x.uint_to_char(1), "a")
81-
with self.assertRaises(RuntimeError):
80+
assert x.uint_to_char(0) == "b"
81+
assert x.uint_to_char(1) == "a"
82+
with pytest.raises(RuntimeError):
8283
x.uint_to_char(2)
8384

84-
self.assertEqual(x.word_to_string([1, 0]), "ab")
85-
self.assertEqual(x.word_to_string([1] * 6), "a" * 6)
86-
with self.assertRaises(RuntimeError):
85+
assert x.word_to_string([1, 0]) == "ab"
86+
assert x.word_to_string([1] * 6) == "a" * 6
87+
with pytest.raises(RuntimeError):
8788
x.word_to_string([2])
8889

8990

90-
def check_initialisation(self, t):
91+
def check_initialisation(t):
9192
ReportGuard(False)
9293
x = t()
9394
x.set_alphabet("ba")
9495
x.add_rule([0, 1], [1, 0])
9596

96-
with self.assertRaises(RuntimeError):
97+
with pytest.raises(RuntimeError):
9798
x.add_rule([0, 1], [2])
9899

99100
S = FroidurePin([Transf([1, 2, 0]), Transf([1, 0, 2])])
100101
S.run()
101102
x.add_rules(S)
102-
self.assertEqual(x.size(), 2)
103+
assert x.size() == 2
103104

104105
x = t()
105106
x.set_alphabet("abBe")
@@ -109,15 +110,15 @@ def check_initialisation(self, t):
109110

110111
x.add_rule("bb", "B")
111112
x.add_rule("BaBa", "abab")
112-
self.assertEqual(x.size(), 24)
113+
assert x.size() == 24
113114

114115
x = t()
115116
x.set_alphabet(1)
116117
x.set_identity(0)
117-
self.assertEqual(x.size(), 1)
118+
assert x.size() == 1
118119

119120

120-
def check_attributes(self, t):
121+
def check_attributes(t):
121122
ReportGuard(False)
122123
x = t()
123124
x.set_alphabet("abBe")
@@ -128,36 +129,33 @@ def check_attributes(self, t):
128129
x.add_rule("BaBa", "abab")
129130
x.run()
130131

131-
self.assertEqual(
132-
list(x.rules()),
133-
[
134-
("ae", "a"),
135-
("ea", "a"),
136-
("be", "b"),
137-
("eb", "b"),
138-
("Be", "B"),
139-
("eB", "B"),
140-
("ee", "e"),
141-
("aa", "e"),
142-
("bB", "e"),
143-
("Bb", "e"),
144-
("bb", "B"),
145-
("BaBa", "abab"),
146-
],
147-
)
148-
self.assertEqual(x.number_of_rules(), 12)
149-
150-
self.assertEqual(x.alphabet(), "abBe")
151-
self.assertFalse(x.has_froidure_pin())
152-
self.assertEqual(x.froidure_pin().size(), 24)
153-
self.assertEqual(x.identity(), "e")
154-
self.assertEqual(x.inverses(), "aBbe")
155-
self.assertFalse(x.is_obviously_infinite())
156-
self.assertTrue(x.is_obviously_finite())
157-
self.assertEqual(x.size(), 24)
158-
159-
160-
def check_operators(self, t):
132+
assert list(x.rules()) == [
133+
("ae", "a"),
134+
("ea", "a"),
135+
("be", "b"),
136+
("eb", "b"),
137+
("Be", "B"),
138+
("eB", "B"),
139+
("ee", "e"),
140+
("aa", "e"),
141+
("bB", "e"),
142+
("Bb", "e"),
143+
("bb", "B"),
144+
("BaBa", "abab"),
145+
]
146+
assert x.number_of_rules() == 12
147+
148+
assert x.alphabet() == "abBe"
149+
assert not x.has_froidure_pin()
150+
assert x.froidure_pin().size() == 24
151+
assert x.identity() == "e"
152+
assert x.inverses() == "aBbe"
153+
assert not x.is_obviously_infinite()
154+
assert x.is_obviously_finite()
155+
assert x.size() == 24
156+
157+
158+
def check_operators(t):
161159
x = t()
162160
x.set_alphabet("abBe")
163161
x.set_identity("e")
@@ -166,31 +164,31 @@ def check_operators(self, t):
166164
x.add_rule("bb", "B")
167165
x.add_rule("BaBa", "abab")
168166
x.run()
169-
self.assertTrue(x.equal_to("bb", "B"))
170-
self.assertTrue(x.equal_to([1, 1], [2]))
167+
assert x.equal_to("bb", "B")
168+
assert x.equal_to([1, 1], [2])
171169

172-
with self.assertRaises(RuntimeError):
170+
with pytest.raises(RuntimeError):
173171
x.equal_to([1, 1], [5])
174172

175-
with self.assertRaises(RuntimeError):
173+
with pytest.raises(RuntimeError):
176174
x.equal_to("aa", "z")
177175

178-
self.assertEqual(x.normal_form("bb"), "B")
179-
self.assertEqual(x.normal_form("B"), "B")
180-
self.assertEqual(x.normal_form([1, 1]), [2])
181-
self.assertEqual(x.normal_form([0, 0]), [3])
176+
assert x.normal_form("bb") == "B"
177+
assert x.normal_form("B") == "B"
178+
assert x.normal_form([1, 1]) == [2]
179+
assert x.normal_form([0, 0]) == [3]
182180

183-
with self.assertRaises(RuntimeError):
181+
with pytest.raises(RuntimeError):
184182
x.normal_form([1, 5])
185-
with self.assertRaises(RuntimeError):
183+
with pytest.raises(RuntimeError):
186184
x.normal_form("z")
187185

188186
if hasattr(t, "rewrite"):
189-
self.assertEqual(x.rewrite("aa"), "")
190-
self.assertEqual(x.rewrite("bb"), "B")
187+
assert x.rewrite("aa") == ""
188+
assert x.rewrite("bb") == "B"
191189

192-
with self.assertRaises(TypeError):
193-
self.assertEqual(x.rewrite("z"))
190+
with pytest.raises(TypeError):
191+
x.rewrite("z")
194192

195193

196194
def check_running_and_state(T):

0 commit comments

Comments
 (0)