Debian Codegraph @

python/tests/test_new_roman_numeral.py

raw
1 import pytest
2
3 from roman_numerals import (
4 MAX,
5 MIN,
6 OutOfRangeError,
7 RomanNumeral,
8 )
9
10
11 def test_zero() -> None:
12 with pytest.raises(OutOfRangeError) as ctx:
13 RomanNumeral(0)
14 msg = str(ctx.value)
15 assert msg == '0 is out of range (must be between 1 and 3,999).'
16
17
18 def test_one() -> None:
19 assert int(RomanNumeral(1)) == 1
20
21
22 def test_MIN() -> None: # NoQA: N802
23 assert int(RomanNumeral(MIN)) == MIN
24
25
26 def test_forty_two() -> None:
27 assert int(RomanNumeral(42)) == 42 # NoQA: PLR2004
28
29
30 def test_three_thousand_nine_hundred_and_ninety_nine() -> None:
31 assert int(RomanNumeral(3_999)) == 3_999 # NoQA: PLR2004
32
33
34 def test_MAX() -> None: # NoQA: N802
35 assert int(RomanNumeral(MAX)) == MAX
36
37
38 def test_four_thousand() -> None:
39 with pytest.raises(OutOfRangeError) as ctx:
40 RomanNumeral(4_000)
41 msg = str(ctx.value)
42 assert msg == '4000 is out of range (must be between 1 and 3,999).'
43
44
45 def test_minus_one() -> None:
46 with pytest.raises(OutOfRangeError) as ctx:
47 RomanNumeral(-1)
48 msg = str(ctx.value)
49 assert msg == '-1 is out of range (must be between 1 and 3,999).'
50
51
52 def test_float() -> None:
53 with pytest.raises(TypeError) as ctx:
54 RomanNumeral(4.2) # type: ignore[arg-type]
55 msg = str(ctx.value)
56 assert msg == "RomanNumeral() argument must be an integer, not 'float'"
57
58
59 def test_mutation() -> None:
60 obj = RomanNumeral(MIN)
61 with pytest.raises(AttributeError, match=r"Cannot set the '_value' attribute."):
62 obj._value = 0 # NoQA: SLF001 # pyright: ignore[reportPrivateUsage]
63 with pytest.raises(AttributeError, match=r"Cannot delete the '_value' attribute."):
64 del obj._value # NoQA: SLF001 # pyright: ignore[reportPrivateUsage]
65
66
67 def test_non_existing_attribute() -> None:
68 obj = RomanNumeral(MIN)
69 with pytest.raises(
70 AttributeError,
71 match=r"'RomanNumeral' object has no attribute 'spam'",
72 ):
73 _ = obj.spam # type: ignore[attr-defined]
74 with pytest.raises(
75 AttributeError,
76 match=r"'RomanNumeral' object has no attribute 'spam'",
77 ):
78 obj.spam = 0
79 with pytest.raises(
80 AttributeError,
81 match=r"'RomanNumeral' object has no attribute 'spam'",
82 ):
83 del obj.spam # type: ignore[attr-defined]