コード例 #1
0
def test_success_datetime_from_timestamp(datetime_tuple, timestamp, tz_name):
    """Test successful calls to datetime_from_timestamp()."""

    if os.name == 'nt' and timestamp > TS_3001_LIMIT:
        # Skip this test case, due to the lower limit on Windows
        return

    # Expected result, as timezone-unaware (but implied UTC)
    exp_dt_unaware = datetime(*datetime_tuple)

    # Expected result, as timezone-aware
    exp_dt = pytz.utc.localize(exp_dt_unaware)

    if tz_name is None:

        # Execute the code to be tested
        act_dt = datetime_from_timestamp(timestamp)

    else:
        tz = pytz.timezone(tz_name)

        # Execute the code to be tested
        act_dt = datetime_from_timestamp(timestamp, tz)

    # Verify the result.
    # Note: timezone-aware datetime objects compare equal according to
    # their effective point in time (e.g. as if normalized to UTC).
    assert act_dt == exp_dt
コード例 #2
0
def test_error_datetime_from_timestamp(timestamp, exc_type):
    """Test failing calls to datetime_from_timestamp()."""

    with pytest.raises(Exception) as exc_info:

        # Execute the code to be tested
        datetime_from_timestamp(timestamp)

    # Verify the result
    assert isinstance(exc_info.value, exc_type)
コード例 #3
0
def x_test_print_max_datetime_from_timestamp():
    """Print the maximum for datetime_from_timestamp()."""
    max_ts = find_max_value(datetime_from_timestamp, 1)
    max_dt = datetime_from_timestamp(max_ts)
    print("\nMax HMC timestamp value for zhmcclient."
          "datetime_from_timestamp(): {} ({!r})".format(max_ts, max_dt))
    sys.stdout.flush()
コード例 #4
0
    def test_success_datetime_from_timestamp(self, datetime_tuple, timestamp):
        """Test successful calls to datetime_from_timestamp()."""

        if os.name == 'nt' and timestamp > TS_3001_LIMIT:
            # Skip this test case, due to the lower limit on Windows
            return

        # Create the expected datetime result (always timezone-aware in UTC)
        dt_unaware = datetime(*datetime_tuple)
        exp_dt = pytz.utc.localize(dt_unaware)

        # Execute the code to be tested
        dt = datetime_from_timestamp(timestamp)

        # Verify the result
        assert dt == exp_dt