antithesis-tests: Fix generate_random_value() on older Python versions

This commit is contained in:
Pekka Enberg
2025-04-26 10:53:31 +03:00
parent a7537be2b6
commit e8bc3086f2

View File

@@ -4,17 +4,16 @@ from antithesis.random import get_random, random_choice
def generate_random_identifier(type: str, num: int):
return ''.join(type, '_', get_random() % num)
def generate_random_value(type: str):
match type:
case 'INTEGER':
return str(get_random() % 100)
case 'REAL':
return '{:.2f}'.format(get_random() % 100 / 100.0)
case 'TEXT':
return f"'{''.join(random_choice(string.ascii_lowercase) for _ in range(5))}'"
case 'BLOB':
return f"x'{''.join(random_choice(string.ascii_lowercase) for _ in range(5)).encode().hex()}'"
case 'NUMERIC':
return str(get_random() % 100)
case _:
return NULL
def generate_random_value(type_str):
if type_str == 'INTEGER':
return str(get_random() % 100)
elif type_str == 'REAL':
return '{:.2f}'.format(get_random() % 100 / 100.0)
elif type_str == 'TEXT':
return f"'{''.join(random_choice(string.ascii_lowercase) for _ in range(5))}'"
elif type_str == 'BLOB':
return f"x'{''.join(random_choice(string.ascii_lowercase) for _ in range(5)).encode().hex()}'"
elif type_str == 'NUMERIC':
return str(get_random() % 100)
else:
return NULL