Build timestamps used to test rounding.
(self, use_float)
| 860 | return (self.time_t_min <= seconds <= self.time_t_max) |
| 861 | |
| 862 | def _rounding_values(self, use_float): |
| 863 | "Build timestamps used to test rounding." |
| 864 | |
| 865 | units = [1, US_TO_NS, MS_TO_NS, SEC_TO_NS] |
| 866 | if use_float: |
| 867 | # picoseconds are only tested to pytime_converter accepting floats |
| 868 | units.append(1e-3) |
| 869 | |
| 870 | values = ( |
| 871 | # small values |
| 872 | 1, 2, 5, 7, 123, 456, 1234, |
| 873 | # 10^k - 1 |
| 874 | 9, |
| 875 | 99, |
| 876 | 999, |
| 877 | 9999, |
| 878 | 99999, |
| 879 | 999999, |
| 880 | # test half even rounding near 0.5, 1.5, 2.5, 3.5, 4.5 |
| 881 | 499, 500, 501, |
| 882 | 1499, 1500, 1501, |
| 883 | 2500, |
| 884 | 3500, |
| 885 | 4500, |
| 886 | ) |
| 887 | |
| 888 | ns_timestamps = [0] |
| 889 | for unit in units: |
| 890 | for value in values: |
| 891 | ns = value * unit |
| 892 | ns_timestamps.extend((-ns, ns)) |
| 893 | for pow2 in (0, 5, 10, 15, 22, 23, 24, 30, 33): |
| 894 | ns = (2 ** pow2) * SEC_TO_NS |
| 895 | ns_timestamps.extend(( |
| 896 | -ns-1, -ns, -ns+1, |
| 897 | ns-1, ns, ns+1 |
| 898 | )) |
| 899 | for seconds in (_testcapi.INT_MIN, _testcapi.INT_MAX): |
| 900 | ns_timestamps.append(seconds * SEC_TO_NS) |
| 901 | if use_float: |
| 902 | # numbers with an exact representation in IEEE 754 (base 2) |
| 903 | for pow2 in (3, 7, 10, 15): |
| 904 | ns = 2.0 ** (-pow2) |
| 905 | ns_timestamps.extend((-ns, ns)) |
| 906 | |
| 907 | # seconds close to _PyTime_t type limit |
| 908 | ns = (2 ** 63 // SEC_TO_NS) * SEC_TO_NS |
| 909 | ns_timestamps.extend((-ns, ns)) |
| 910 | |
| 911 | return ns_timestamps |
| 912 | |
| 913 | def _check_rounding(self, pytime_converter, expected_func, |
| 914 | use_float, unit_to_sec, value_filter=None): |
no test coverage detected