Revised the way to import from the datetime package, to avoid name conflict with the common "date" and "time" names.

This commit is contained in:
2023-04-26 13:17:31 +08:00
parent c11ae23885
commit 359c335662
30 changed files with 156 additions and 152 deletions

View File

@ -17,8 +17,8 @@
"""The test for the account management.
"""
import datetime as dt
import unittest
from datetime import timedelta, date
import httpx
from flask import Flask
@ -461,7 +461,7 @@ class AccountTestCase(unittest.TestCase):
account = Account.find_by_code(CASH.code)
self.assertIsNotNone(account)
account.created_at \
= account.created_at - timedelta(seconds=5)
= account.created_at - dt.timedelta(seconds=5)
account.updated_at = account.created_at
db.session.commit()
@ -592,7 +592,7 @@ class AccountTestCase(unittest.TestCase):
add_journal_entry(self.client,
form={"csrf_token": self.csrf_token,
"next": NEXT_URI,
"date": date.today().isoformat(),
"date": dt.date.today().isoformat(),
"currency-1-code": "USD",
"currency-1-credit-1-account_code": BANK.code,
"currency-1-credit-1-amount": "20"})

View File

@ -17,8 +17,8 @@
"""The test for the currency management.
"""
import datetime as dt
import unittest
from datetime import timedelta, date
import httpx
from flask import Flask
@ -384,7 +384,7 @@ class CurrencyTestCase(unittest.TestCase):
currency = db.session.get(Currency, USD.code)
self.assertIsNotNone(currency)
currency.created_at \
= currency.created_at - timedelta(seconds=5)
= currency.created_at - dt.timedelta(seconds=5)
currency.updated_at = currency.created_at
db.session.commit()
@ -534,7 +534,7 @@ class CurrencyTestCase(unittest.TestCase):
add_journal_entry(self.client,
form={"csrf_token": self.csrf_token,
"next": NEXT_URI,
"date": date.today().isoformat(),
"date": dt.date.today().isoformat(),
"currency-1-code": EUR.code,
"currency-1-credit-1-account_code": "1111-001",
"currency-1-credit-1-amount": "20"})

View File

@ -17,8 +17,8 @@
"""The test for the description editor.
"""
import datetime as dt
import unittest
from datetime import date
from flask import Flask
@ -149,7 +149,7 @@ def get_form_data(csrf_token: str) -> list[dict[str, str]]:
:param csrf_token: The CSRF token.
:return: A list of the form data.
"""
journal_entry_date: str = date.today().isoformat()
journal_entry_date: str = dt.date.today().isoformat()
return [{"csrf_token": csrf_token,
"next": NEXT_URI,
"date": journal_entry_date,

View File

@ -17,8 +17,8 @@
"""The test for the journal entry management.
"""
import datetime as dt
import unittest
from datetime import date, timedelta
from decimal import Decimal
import httpx
@ -500,7 +500,7 @@ class CashReceiptJournalEntryTestCase(unittest.TestCase):
journal_entry = db.session.get(JournalEntry, journal_entry_id)
self.assertIsNotNone(journal_entry)
journal_entry.created_at \
= journal_entry.created_at - timedelta(seconds=5)
= journal_entry.created_at - dt.timedelta(seconds=5)
journal_entry.updated_at = journal_entry.created_at
db.session.commit()
@ -576,7 +576,7 @@ class CashReceiptJournalEntryTestCase(unittest.TestCase):
self.client,
form={"csrf_token": self.csrf_token,
"next": NEXT_URI,
"date": date.today().isoformat(),
"date": dt.date.today().isoformat(),
"currency-1-code": line_item.currency_code,
"currency-1-debit-1-original_line_item_id": line_item.id,
"currency-1-debit-1-account_code": line_item.account_code,
@ -1112,7 +1112,7 @@ class CashDisbursementJournalEntryTestCase(unittest.TestCase):
journal_entry = db.session.get(JournalEntry, journal_entry_id)
self.assertIsNotNone(journal_entry)
journal_entry.created_at \
= journal_entry.created_at - timedelta(seconds=5)
= journal_entry.created_at - dt.timedelta(seconds=5)
journal_entry.updated_at = journal_entry.created_at
db.session.commit()
@ -1773,7 +1773,7 @@ class TransferJournalEntryTestCase(unittest.TestCase):
journal_entry = db.session.get(JournalEntry, journal_entry_id)
self.assertIsNotNone(journal_entry)
journal_entry.created_at \
= journal_entry.created_at - timedelta(seconds=5)
= journal_entry.created_at - dt.timedelta(seconds=5)
journal_entry.updated_at = journal_entry.created_at
db.session.commit()
@ -2124,9 +2124,9 @@ class JournalEntryReorderTestCase(unittest.TestCase):
with self.app.app_context():
journal_entry_1: JournalEntry = db.session.get(JournalEntry, id_1)
journal_entry_date_2: date = journal_entry_1.date
journal_entry_date_1: date \
= journal_entry_date_2 - timedelta(days=1)
journal_entry_date_2: dt.date = journal_entry_1.date
journal_entry_date_1: dt.date \
= journal_entry_date_2 - dt.timedelta(days=1)
journal_entry_1.date = journal_entry_date_1
journal_entry_1.no = 3
journal_entry_2: JournalEntry = db.session.get(JournalEntry, id_2)
@ -2176,7 +2176,8 @@ class JournalEntryReorderTestCase(unittest.TestCase):
self.__get_add_disbursement_form())
with self.app.app_context():
journal_entry_date: date = db.session.get(JournalEntry, id_1).date
journal_entry_date: dt.date \
= db.session.get(JournalEntry, id_1).date
response = self.client.post(
f"{PREFIX}/dates/{journal_entry_date.isoformat()}",

View File

@ -17,8 +17,8 @@
"""The test for the options.
"""
import datetime as dt
import unittest
from datetime import datetime, timedelta
import httpx
from flask import Flask
@ -286,7 +286,8 @@ class OptionTestCase(unittest.TestCase):
with self.app.app_context():
option = db.session.get(Option, "recurring")
self.assertIsNotNone(option)
timestamp: datetime = option.created_at - timedelta(seconds=5)
timestamp: dt.datetime \
= option.created_at - dt.timedelta(seconds=5)
option.created_at = timestamp
option.updated_at = timestamp
db.session.commit()

View File

@ -17,8 +17,8 @@
"""The test for the reports.
"""
import datetime as dt
import unittest
from datetime import date
import httpx
from flask import Flask
@ -446,11 +446,11 @@ class ReportTestData(BaseTestData):
"""The report test data."""
def _init_data(self) -> None:
today: date = date.today()
today: dt.date = dt.date.today()
year: int = today.year - 5
month: int = today.month
while True:
j_date: date = date(year, month, 5)
j_date: dt.date = dt.date(year, month, 5)
if j_date > today:
break
self._add_simple_journal_entry(

View File

@ -19,9 +19,9 @@
"""
from __future__ import annotations
import datetime as dt
import typing as t
from abc import ABC, abstractmethod
from datetime import date, timedelta
from decimal import Decimal
from secrets import randbelow
@ -167,7 +167,8 @@ class JournalEntryData:
:param is_update: True for an update operation, or False otherwise
:return: The journal entry as a form.
"""
journal_entry_date: date = date.today() - timedelta(days=self.days)
journal_entry_date: dt.date \
= dt.date.today() - dt.timedelta(days=self.days)
form: dict[str, str] = {"csrf_token": csrf_token,
"next": next_uri,
"date": journal_entry_date.isoformat()}
@ -240,7 +241,8 @@ class BaseTestData(ABC):
existing_j_id: set[int] = {x["id"] for x in self.__journal_entries}
existing_l_id: set[int] = {x["id"] for x in self.__line_items}
journal_entry_data.id = self.__new_id(existing_j_id)
j_date: date = date.today() - timedelta(days=journal_entry_data.days)
j_date: dt.date \
= dt.date.today() - dt.timedelta(days=journal_entry_data.days)
self.__journal_entries.append(
{"id": journal_entry_data.id,
"date": j_date,
@ -303,7 +305,7 @@ class BaseTestData(ABC):
existing_id.add(obj_id)
return obj_id
def __next_j_no(self, j_date: date) -> int:
def __next_j_no(self, j_date: dt.date) -> int:
"""Returns the next journal entry number in a day.
:param j_date: The journal entry date.

View File

@ -17,7 +17,7 @@
"""The data reset for the Mia! Accounting demonstration website.
"""
from datetime import date, timedelta
import datetime as dt
from flask import Flask, Blueprint, url_for, flash, redirect, session, \
render_template, current_app
@ -116,14 +116,14 @@ class SampleData(BaseTestData):
:return: None.
"""
today: date = date.today()
today: dt.date = dt.date.today()
days: int
year: int
month: int
# Recurring in USD
j_date: date = date(today.year - 5, today.month, today.day)
j_date = j_date + timedelta(days=(4 - j_date.weekday()))
j_date: dt.date = dt.date(today.year - 5, today.month, today.day)
j_date = j_date + dt.timedelta(days=(4 - j_date.weekday()))
days = (today - j_date).days
while True:
if days < 0:
@ -147,7 +147,7 @@ class SampleData(BaseTestData):
if month > 12:
year = year + 1
month = 1
days = (today - date(year, month, 1)).days
days = (today - dt.date(year, month, 1)).days
if days < 0:
break
self.__add_journal_entry(
@ -159,12 +159,12 @@ class SampleData(BaseTestData):
:return: None.
"""
today: date = date.today()
today: dt.date = dt.date.today()
year: int = today.year - 5
month: int = today.month
while True:
days: int = (today - date(year, month, 5)).days
days: int = (today - dt.date(year, month, 5)).days
if days < 0:
break
self.__add_journal_entry(

View File

@ -17,8 +17,8 @@
"""The common test libraries for the journal entry test cases.
"""
import datetime as dt
import re
from datetime import date
from decimal import Decimal
from secrets import randbelow
@ -41,7 +41,7 @@ def get_add_form(csrf_token: str) -> dict[str, str]:
"""
return {"csrf_token": csrf_token,
"next": NEXT_URI,
"date": date.today().isoformat(),
"date": dt.date.today().isoformat(),
"currency-0-code": "USD",
"currency-0-debit-0-no": "16",
"currency-0-debit-0-account_code": Accounts.CASH,