예제 #1
0
    def test_exception(self):
        async def returning(value):
            return value

        with pytest.raises(ActivityLeak) as exc_info:
            run(returning(1138))
        assert exc_info.value.result == 1138
예제 #2
0
    def run_test(*args, **kwargs):
        test_completed = False

        async def complete_test_case():
            nonlocal test_completed
            await test_case(*args, **kwargs)
            test_completed = True
        run(complete_test_case())
        if not test_completed:
            raise UnfinishedTest(test_case)
예제 #3
0
    def run_test(*args, **kwargs):
        gc.collect()  # force collecting leftover coroutines
        test_completed = False

        async def complete_test_case():
            nonlocal test_completed
            await test_case(*args, **kwargs)
            test_completed = True

        run(complete_test_case())
        if not test_completed:
            raise UnfinishedTest(test_case)
예제 #4
0
 def run_test(*args, **kwargs):
     # pytest currently ignores __tracebackhide__ if we re-raise
     # https://github.com/pytest-dev/pytest/issues/1904
     __tracebackhide__ = True
     # >>> This is not the frame you are looking for. Do read on. <<<
     return run(test_case(*args, **kwargs))
예제 #5
0
    def run(self, until=None):
        monitor.SIMULATION_START = pytime.time()

        print(f"[lapis-{monitor.SIMULATION_START}] running until {until}")
        run(self._simulate(until))
예제 #6
0
 def run(self, until=None):
     print(f"running until {until}")
     run(self._simulate(until))
예제 #7
0
    def __repr__(self):
        return "<%s: %s>" % (self.__class__.__name__, self.storage or id(self))


if __name__ == "__main__":
    from usim import run, Scope

    async def report_load(pipe: MonitoredPipe):
        async for event in pipe.load():
            requested_tp = event.requested_throughput
            available_tp = event.available_throughput
            print(f"{time.now:6.0f}:"
                  f"{requested_tp} \t"
                  f"[{requested_tp / available_tp * 100:03.0f}%]")

    async def perform_load(pipe: MonitoredPipe, delay, amount):
        await (time + delay)
        await pipe.transfer(amount, pipe.throughput / 2)

    async def main():
        pipe = MonitoredPipe(128)
        async with Scope() as scope:
            scope.do(report_load(pipe), volatile=True)
            scope.do(perform_load(pipe, 0, 512))
            scope.do(perform_load(pipe, 4, 1024))
            scope.do(perform_load(pipe, 6, 128))
            scope.do(perform_load(pipe, 12, 1024))

    run(main())
예제 #8
0
def perform(end: float = 1000000):
    run(car(end))
예제 #9
0
 def test_after_sim(self):
     run()
     self.test_no_sim()