Skip to content

Commit

Permalink
refactor: simplify if statements
Browse files Browse the repository at this point in the history
Signed-off-by: F.N. Claessen <[email protected]>
  • Loading branch information
Flix6x committed Jan 16, 2025
1 parent 251e7d0 commit 0c0d939
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions development_utilities/gen_unit_test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def generate_json_test_data_for_field(field_type: Type):
value = bool(random.randint(0, 1))
elif field_type is float:
value = random.random() * 9000.0
elif field_type is AwareDatetime:
elif field_type in (AwareDatetime, datetime.datetime):
# Generate a timezone-aware datetime
value = datetime.datetime(
year=random.randint(2020, 2023),
Expand All @@ -124,18 +124,6 @@ def generate_json_test_data_for_field(field_type: Type):
second=random.randint(0, 59),
tzinfo=datetime.timezone(datetime.timedelta(hours=random.randint(-12, 14))),
)
elif field_type is datetime.datetime:
value = datetime.datetime(
year=random.randint(2020, 2023),
month=random.randint(1, 12),
day=random.randint(1, 28),
hour=random.randint(0, 23),
minute=random.randint(0, 59),
second=random.randint(0, 59),
tzinfo=datetime.timezone(
offset=datetime.timedelta(hours=random.randint(0, 2))
),
)
elif field_type is uuid.UUID:
value = uuid.uuid4()
else:
Expand Down Expand Up @@ -237,7 +225,7 @@ def dump_test_data_as_json_field_for(test_data, field_type: Type):
value = test_data
elif field_type is float:
value = test_data
elif field_type is AwareDatetime or field_type is datetime.datetime:
elif field_type in (AwareDatetime, datetime.datetime):
test_data: datetime.datetime
value = test_data.isoformat()
elif field_type is uuid.UUID:
Expand Down

0 comments on commit 0c0d939

Please sign in to comment.