Пример #1
0
def test_datetime():
    """Test loading the :class:`datetime.datetime` from a string"""
    # Check the type
    o = CheckIn("Joe", Pokeball.poke_ball, "Pokemart", "2016-09-10 12:04:02")
    assert isinstance(o.time, datetime.datetime)

    # Bad time
    with pytest.raises(ValueError):
        CheckIn("Joe", Pokeball.poke_ball, "Pokemart", "2016-09-10 12:00:")

    # Bad date
    with pytest.raises(ValueError):
        CheckIn("Joe", Pokeball.poke_ball, "Pokemart", "2016-09- 12:00:00")

    # Good date/time
    o = CheckIn("Joe", Pokeball.poke_ball, "Pokemart", "2016-09-10 12:04:02")

    # Check that fields are assigned properly
    assert o.time.day == 10
    assert o.time.month == 9
    assert o.time.year == 2016
    assert o.time.hour == 12
    assert o.time.minute == 4
    assert o.time.second == 2
    assert o.time.microsecond == 0
Пример #2
0
def test_rendezvous():
    """Test our rendezvous generator"""
    timeline = CheckInTimeline()
    timeline.add(
        CheckIn("Alice", Pokeball.poke_ball, "Pokemart",
                "1970-01-02 02:53:00"))

    timeline.add(
        CheckIn("Bob", Pokeball.poke_ball, "Pokemart", "1970-01-02 03:52:00"))

    for i, agent_pair in enumerate(timeline.rendezvous()):
        # Gotta be a tuple of length 2
        assert isinstance(agent_pair, tuple)
        assert len(agent_pair) == 2

        # Unpack 'em
        a1, a2 = agent_pair

        # Check the types
        assert isinstance(a1, CheckIn)
        assert isinstance(a2, CheckIn)

        # Check that we've got our agents
        assert "Alice" in (a1.name, a2.name)
        assert "Bob" in (a1.name, a2.name)

    # We only looped one time, so 'i' was set to zero, and that's it.
    assert i == 0
Пример #3
0
def test_ge():
    """Test >= operator"""
    o1 = CheckIn("Joe", Pokeball.poke_ball, "Pokemart", "2016-09-10 12:00:00")
    o2 = CheckIn("Jane", Pokeball.poke_ball, "Pokemart", "2016-09-10 12:30:00")
    assert not (o1 >= o2)
    assert o1 >= o1
    assert o2 >= o2
    assert o2 >= o1
Пример #4
0
def random_timed_checkins(count=100):
    """A helper function that returns CheckIns with random times

    Note that the names and locations will all be the same.

    :param int count: The number of CheckIns to return

    :return: a list of CheckIn instances in a random order.
    """
    # Generate a list of random, unique CheckIns
    checkins = []
    time = datetime.fromtimestamp(0)
    for _ in range(count):
        time += timedelta(minutes=random.randint(1, 59))
        c = CheckIn("Bob", Pokeball.poke_ball, "Pokemart", str(time))
        checkins.append(c)

    # Shuffle up the CheckIns
    random.shuffle(checkins)

    return checkins
Пример #5
0
def test_str():
    """Test str construction"""
    o = CheckIn("Tom", Pokeball.poke_ball, "Pokemart", "2016-09-10 12:04:02")
    assert str(o) == "Tom at Pokemart with a Poke Ball (2016-09-10 12:04:02)"
Пример #6
0
def test_lt():
    """Test < operator"""
    o1 = CheckIn("Joe", Pokeball.poke_ball, "Pokemart", "2016-09-10 12:00:00")
    o2 = CheckIn("Jane", Pokeball.poke_ball, "Pokemart", "2016-09-10 12:30:00")
    assert o1 < o2
    assert not (o2 < o1)