@@ -233,7 +233,19 @@ def test_money(data, expected):
233
233
]))
234
234
assert expected == bool (re .match (money_regex , data ))
235
235
236
- def test_string_contains_money ():
236
+ STRING_MONEY_REGEX_TEST_CASES = [
237
+ ("billed amount of $" , False ),
238
+ ("billed amount of $0.50" , True ),
239
+ ("billed amount of $123.50" , True ),
240
+ ("billed amount of $123" , True ),
241
+ ("billed amount of $123,456" , True ),
242
+ ("billed amount of $123,456,789" , True ),
243
+ ("billed amount of $123,456,789.50" , True ),
244
+ ("billed amount of $123." , True ),
245
+ ("billed amount of $123,456,789." , True ),
246
+ ]
247
+ @pytest .mark .parametrize ("data, expected" , STRING_MONEY_REGEX_TEST_CASES )
248
+ def test_string_contains_money (data , expected ):
237
249
money_regex = re .compile ('|' .join ([
238
250
r'\b\$?(\d*\.\d{1,2})' , # e.g., $.50, .50, $1.50, $.5, .5
239
251
r'\b\$?(\d+)' , # e.g., $500, $5, 500, 5
@@ -242,9 +254,8 @@ def test_string_contains_money():
242
254
r'\b\$?(\d{1,3},\d{3})*\.?' , # e.g., $123,456.5, $1,234, $12,345
243
255
r'\b\$?(\d{1,3},\d{3})*\.\d{1,2}' , # e.g., $123,456.5, $1,234, $12,345
244
256
]))
245
- str = "billed amount of $52,221,646.74."
246
- result = re .findall (money_regex , str )#.groups()
257
+ result = re .findall (money_regex , data )
247
258
#print(f"test_money result: {result}")
248
259
assert result
249
260
assert result [0 ]
250
- assert re .match (money_regex , str )
261
+ assert re .match (money_regex , data )
0 commit comments