def test_set_flow_order_processes():
    pm = ProcessManager()

    class TestProcess1(Process):
        def definition(self, user, **kwargs):
            va = True

    pm.attach_process(TestProcess1)

    class TestProcess2(Process):
        def definition(self, user, **kwargs):
            bene = True

    pm.attach_process(TestProcess2)

    pm.set_flow(sequence=('TestProcess1', 'TestProcess2'))
    assert pm.flow['from'][1] == 'TestProcess1' and pm.flow['to'][
        1] == 'TestProcess2'
def test_unblock_flow():
    pm = ProcessManager()

    class TestProcess1(Process):
        def definition(self, user, **kwargs):
            va = True

    pm.attach_process(TestProcess1)

    class TestProcess2(Process):
        def definition(self, user, **kwargs):
            bene = True

    pm.attach_process(TestProcess2)

    pm.block_flow()
    pm.unblock_flow()
    pm.set_flow(sequence=('TestProcess1', 'TestProcess2'))
def test_reset_flow():
    pm = ProcessManager()

    class TestProcess1(Process):
        def definition(self, user, **kwargs):
            va = True

    pm.attach_process(TestProcess1)

    class TestProcess2(Process):
        def definition(self, user, **kwargs):
            bene = True

    pm.attach_process(TestProcess2)

    pm.set_flow(sequence=('TestProcess1', 'TestProcess2'))
    pm.reset_flow()

    assert pm.flow.empty == True  # assert if dataframe is empty or not
def test_set_flow_cant_change_flow():
    pm = ProcessManager()

    class TestProcess1(Process):
        def definition(self, user, **kwargs):
            va = True

    pm.attach_process(TestProcess1)

    class TestProcess2(Process):
        def definition(self, user, **kwargs):
            bene = True

    pm.attach_process(TestProcess2)

    pm.set_flow(sequence=['TestProcess1', 'TestProcess2'])
    em = EventManager(pm)

    with pytest.raises(ValueError):
        pm.set_flow(sequence=['TestProcess2', 'TestProcess1'])
def test_block_flow():
    pm = ProcessManager()

    class TestProcess1(Process):
        def definition(self, user, **kwargs):
            va = True

    pm.attach_process(TestProcess1)

    class TestProcess2(Process):
        def definition(self, user, **kwargs):
            bene = True

    pm.attach_process(TestProcess2)

    pm.block_flow()

    with pytest.raises(ValueError):
        assert pm.set_flow(sequence=('TestProcess1', 'TestProcess2'))
Exemple #6
0
                'station': cyclist.to_station
            }),
            which='any',
        )
        dest_dock = response.events[0].resource
        bike.set_checkpoint(f'Docked on {dest_dock.name} at {dest_dock.station}')

        # Finish cycle
        cyclist.releases(bike_resource)
        cyclist.set_checkpoint(
            f'Left {bike_resource.name} at {dest_dock.station}'
        )

pm.attach_process(IncludeBike)
pm.attach_process(Cycle)
pm.set_flow(initial_process='IncludeBike')
pm.set_flow(final_process='IncludeBike')
pm.set_flow(initial_process='Cycle')
pm.set_flow(final_process='Cycle')

em = EventManager(pm)

# Custom Resource class for bikes
class BikeResource(Resource):
    @property
    def station(self):
        # Bike-user and bike-resource have the same name
        dock = self.rm.get_resources(by_user=self.name)
        if len(dock) == 0:
            return None
        else: