Beispiel #1
0
    def test_active_start_after_one_timestep(self):
        start_time = self.model_time + timedelta(seconds=self.time_step)

        mv = PyMover(active_range=(start_time, InfDateTime('inf')))

        mv.prepare_for_model_step(self.sc, self.time_step, self.model_time)

        # model_time + time_step should be within active range
        assert mv.active is False
Beispiel #2
0
    def test_active_start_after_one_timestep(self):
        start_time = self.model_time + timedelta(seconds=self.time_step)

        mv = PyMover(active_range=(start_time, InfDateTime('inf')))

        mv.prepare_for_model_step(self.sc, self.time_step, self.model_time)

        # model_time + time_step should be within active range
        assert mv.active is False
Beispiel #3
0
def test_get_move():
    '''
    assert base class get_move returns an array of nan[s]
    '''
    time_step = 15 * 60  # seconds
    model_time = datetime(2012, 8, 20, 13)
    sc = sample_sc_release(10, (0, 0, 0))  # no used for anything

    mv = PyMover()
    delta = mv.get_move(sc, time_step, model_time)

    assert np.all(np.isnan(delta))
Beispiel #4
0
def test_get_move():
    '''
    assert base class get_move returns an array of nan[s]
    '''
    time_step = 15 * 60  # seconds
    model_time = datetime(2012, 8, 20, 13)
    sc = sample_sc_release(10, (0, 0, 0))  # no used for anything

    mv = PyMover()
    delta = mv.get_move(sc, time_step, model_time)

    assert np.all(np.isnan(delta))
Beispiel #5
0
def test_default_properties():
    mover = PyMover()

    #assert mover.name == 'PyMover'
    assert mover.on is True

    assert mover.active_range == (InfDateTime('-inf'), InfDateTime('inf'))

    #assert mover.array_types == set()
    assert mover.make_default_refs is True

    assert mover.default_num_method == 'RK2'
Beispiel #6
0
    def test_active_start_modeltime(self):
        mv = PyMover(active_range=(self.model_time, InfDateTime('inf')))
        mv.prepare_for_model_step(self.sc, self.time_step, self.model_time)

        # model_time should be within active range
        assert mv.active is True
Beispiel #7
0
    def test_active_default(self):
        mv = PyMover()  # active range defaults to (-Inf, Inf)
        mv.prepare_for_model_step(self.sc, self.time_step, self.model_time)

        # model_time should be within range at any datetime.
        assert mv.active is True
Beispiel #8
0
class TestActive:
    time_step = 15 * 60  # seconds
    model_time = datetime(2012, 8, 20, 13)
    sc = sample_sc_release(1, (0, 0, 0))  # no used for anything
    mv = PyMover()

    def test_active_default(self):
        mv = PyMover()  # active range defaults to (-Inf, Inf)
        mv.prepare_for_model_step(self.sc, self.time_step, self.model_time)

        # model_time should be within range at any datetime.
        assert mv.active is True

    def test_active_start_modeltime(self):
        mv = PyMover(active_range=(self.model_time, InfDateTime('inf')))
        mv.prepare_for_model_step(self.sc, self.time_step, self.model_time)

        # model_time should be within active range
        assert mv.active is True

    def test_active_start_after_one_timestep(self):
        start_time = self.model_time + timedelta(seconds=self.time_step)

        mv = PyMover(active_range=(start_time, InfDateTime('inf')))

        mv.prepare_for_model_step(self.sc, self.time_step, self.model_time)

        # model_time + time_step should be within active range
        assert mv.active is False

    def test_active_start_after_half_timestep(self):
        self.mv.active_range = ((self.model_time +
                                 timedelta(seconds=self.time_step / 2)),
                                InfDateTime('inf'))

        self.mv.prepare_for_model_step(self.sc, self.time_step,
                                       self.model_time)

        # model_time + time_step / 2 should be within active range
        assert self.mv.active is True

    # Next test just some more borderline cases that active is set correctly
    def test_active_stop_greater_than_timestep(self):
        self.mv.active_range = (self.model_time,
                                (self.model_time +
                                 timedelta(seconds=1.5 * self.time_step)))

        self.mv.prepare_for_model_step(self.sc, self.time_step,
                                       self.model_time)

        # model_time + 1.5 * time_step should be within active range
        assert self.mv.active is True

    def test_active_stop_after_half_timestep(self):
        self.mv.active_range = (self.model_time,
                                (self.model_time +
                                 timedelta(seconds=0.5 * self.time_step)))

        self.mv.prepare_for_model_step(self.sc, self.time_step,
                                       self.model_time)

        # model_time + 1.5 * time_step should be within active range
        assert self.mv.active is True

    def test_active_stop_less_than_half_timestep(self):
        self.mv.active_range = (self.model_time,
                                (self.model_time +
                                 timedelta(seconds=0.25 * self.time_step)))

        self.mv.prepare_for_model_step(self.sc, self.time_step,
                                       self.model_time)

        # current_model_time = active_stop
        assert self.mv.active is False
Beispiel #9
0
def test_exceptions():
    with raises(ValueError):
        now = datetime.now()
        _mover = PyMover(active_range=(now, now))
Beispiel #10
0
    def test_active_start_modeltime(self):
        mv = PyMover(active_range=(self.model_time, InfDateTime('inf')))
        mv.prepare_for_model_step(self.sc, self.time_step, self.model_time)

        # model_time should be within active range
        assert mv.active is True
Beispiel #11
0
    def test_active_default(self):
        mv = PyMover()  # active range defaults to (-Inf, Inf)
        mv.prepare_for_model_step(self.sc, self.time_step, self.model_time)

        # model_time should be within range at any datetime.
        assert mv.active is True