Ejemplo n.º 1
0
def test_error(datetime_, exc_type):
    """Test failing calls to timestamp_from_datetime()."""

    with pytest.raises(Exception) as exc_info:

        # Execute the code to be tested
        timestamp_from_datetime(datetime_)

    # Verify the result
    assert isinstance(exc_info.value, exc_type)
Ejemplo n.º 2
0
def test_success(datetime_tuple, timestamp, tz_name):
    """Test successful calls to timestamp_from_datetime()."""

    # Create a timezone-naive datetime object
    dt = datetime(*datetime_tuple)
    offset = 0  # because of default UTC

    if tz_name is not None:
        # Make the datetime object timezone-aware
        tz = pytz.timezone(tz_name)
        offset = tz.utcoffset(dt).total_seconds()
        dt = tz.localize(dt)

    exp_ts = timestamp - offset * 1000

    # Execute the code to be tested
    ts = timestamp_from_datetime(dt)

    # Verify the result
    assert ts == exp_ts
Ejemplo n.º 3
0
def test_datetime_max():
    """Test timestamp_from_datetime() with datetime.max."""

    # The test is that it does not raise an exception:
    timestamp_from_datetime(datetime.max)