pytest tests.test_tools

tests.test_tools.attr_error(attr: str, expected: Any, observed: Any)

Returns a boiler-plate message fragment consisting of an attribute name and expected and observed values

Parameters
  • attr (str) – attribute name

  • expected (Any) – the expected value

  • observed (Any) – the observed value

Returns

None

tests.test_tools.compare_hms(time1, time2) bool

Compares the hour, minutes and seconds of two datetime.time objects. This avoids false inequalities based on microsecond level variances

Parameters
  • time1 (datetime.time) – the first of a pair of times to be compared

  • time2 (datetime.time) – the second of a pair of times to be compared

Returns

are the times equal

Return type

bool

tests.test_tools.compare_mdyhms(datetime1: datetime, datetime2: datetime) bool

Compares the day, month, year, hour, minutes and seconds of two datetime.datetime objects. This avoids false inequalities based on microsecond level variances

Parameters
  • datetime1 (datetime.datetime) – the first of a pair of datetimes to be compared

  • datetime2 (datetime.datetime) – the second of a pair of datetimes to be compared

Returns

are the datetimes equal

Return type

bool

tests.test_tools.compare_object(obj1: Any, obj2: Any) bool

Compare two objects by comparing the entries in their __dict__ property

Parameters
  • obj1 (Any) – the first of a pair of objects to be compared

  • obj2 (Any) – the second of a pair of objects to be compared

Returns

are the objects equal

Return type

bool

tests.test_tools.decode_date(logger: Logger, date_fmt: str, date_str: str) Optional[date]

Decode a date value from the provided string, using the format specified the provided format string. This method raises a ValueError exception if a date can’t be derived from the provided string value

Parameters
  • logger (logging.Logger) – a logger that will be written to if the decode fails

  • date_fmt (str) – the strftime format spec with which the date string was formatted

  • date_str (str) – the formatted date string

Returns

the date value decoded from the date string

Return type

Optional[datetime.date]

tests.test_tools.decode_decimal(dec_str: str) tuple[decimal.Decimal, str]

Decodes a Decimal value from the provided string value This method will properly handle strings in which a U.O.M. is appended to the Decimal value

Parameters

dec_str (str) – a string representation of a Decimal value

Returns

a Decimal value

Return type

decimal.Decimal

tests.test_tools.decode_int(int_str: str) tuple[int, str]

Decodes an integer from the provided string value. This method will properly handle strings in which a U.O.M. is appended to the integer value

Parameters

int_str (str) – a string representation of an integer

Returns

an integer value

Return type

int

tests.test_tools.decode_time(logger: Logger, time_fmt: str, time_str: str) Optional[time]

Decode a time value from the provided string, using the format specified the provided format string. A ValueError exception is raised if a time can’t be derived from the provided string

Parameters
  • logger (logging.Logger) – a logger that will be written to if the decode fails

  • time_fmt (str) – the strftime format spec with which the time string was formatted

  • time_str (str) – the formatted time string

Returns

the time value decoded from the time string

Return type

Optional[datetime.time]

tests.test_tools.dict_diff(name: str, exp_list: dict, obs_list: dict)

Formats a message fragment to be used if the contents of two dicts are unequal

Parameters
  • name (str) – the name of the attribute that the dicts represent

  • exp_list (dict) – a dict containing the expected values

  • obs_list – a dict containing the observed values

Returns

a message fragment

Return type

str