File tree Expand file tree Collapse file tree 1 file changed +18
-7
lines changed Expand file tree Collapse file tree 1 file changed +18
-7
lines changed Original file line number Diff line number Diff line change 3
3
import dataclasses
4
4
import decimal
5
5
import fractions
6
+ import sys
6
7
7
8
import pytest
8
9
@@ -128,13 +129,23 @@ def test_unit_symbol(unit):
128
129
)
129
130
def test_format (measurement , format_spec ):
130
131
if format_spec and isinstance (measurement .magnitude , fractions .Fraction ):
131
- with pytest .raises (TypeError ):
132
- format (measurement , format_spec )
133
- else :
134
- formatted = format (measurement .magnitude , format_spec )
135
- if measurement .prefix .symbol or measurement ._unit_symbol :
136
- formatted += f" { measurement .prefix .symbol } { measurement ._unit_symbol } "
137
- assert format (measurement , format_spec ) == formatted
132
+ if sys .version_info < (3 , 12 ):
133
+ with pytest .raises (TypeError ):
134
+ format (measurement , format_spec )
135
+ return
136
+
137
+ if format_spec == "n" :
138
+ with pytest .raises (
139
+ ValueError ,
140
+ match = "Invalid format specifier 'n' for object of type 'Fraction'" ,
141
+ ):
142
+ format (measurement , format_spec )
143
+ return
144
+
145
+ formatted = format (measurement .magnitude , format_spec )
146
+ if measurement .prefix .symbol or measurement ._unit_symbol :
147
+ formatted += f" { measurement .prefix .symbol } { measurement ._unit_symbol } "
148
+ assert format (measurement , format_spec ) == formatted
138
149
139
150
140
151
def test_str (measurement ):
You can’t perform that action at this time.
0 commit comments