def test_should_not_block_on_many_writes_if_no_input_being_received_by_the_process( self): process = Process("./tests/models/output-once.sh") process.start() for _ in range(100000): process.write({'aaa': 'bbb'})
def test_should_set_running_to_true_immediately_after_start(self): process = Process("./tests/models/output-echo.sh") process.start() assert process.running process.stop() while process.running: time.sleep(0.1)
def test_should_read_json_document(self): process = Process("./tests/models/output-once.sh") process.start() while process.read() != {'key1': 'value1', 'key2': 2}: time.sleep(0.1) process.stop()
def test_should_not_let_start_the_process_twice(self): process = Process("./tests/models/output-echo.sh") process.start() with pytest.raises(Exception): process.start() process.stop() while process.running: time.sleep(0.1)
def test_should_kill_process_on_stop(self): process = Process("./tests/models/output-echo.sh") process.start() while not process.running: time.sleep(0.1) process.stop() while process.running: time.sleep(0.1)
def test_should_read_long_json_documents(self): process = Process("./tests/models/output-long.sh") process.start() time.sleep(1) doc = process.read() assert doc is not None assert len(doc) == 65
def test_should_let_start_the_process_again_after_it_terminated_voluntarily( self): process = Process("./tests/models/terminate-voluntarily.sh") process.start() while process.running: time.sleep(0.1) process.start() while not process.running: time.sleep(0.1)
def test_should_read_and_write(self): process = Process("./tests/models/output-echo.sh") process.start() time.sleep(1) assert process.read() is None for value in ['value1', 'value2', 'value3']: process.write({'key': value}) while process.read() != {'key': value}: time.sleep(0.1) process.stop()
def test_should_terminate_process_on_broken_input_pipe(self): process = Process("./tests/models/break-pipe.sh") process.start() # so the process has some time to break the pipe time.sleep(1) for _ in range(10): process.write({'aaa': 'bbb'}) time.sleep(5) assert process.running is False
def test_should_skip_invalid_json_documents(self): process = Process("./tests/models/output-invalid.sh") process.start() while process.read() != {'key': 'value1'}: time.sleep(0.1) while process.read() != {'key': 'value2'}: time.sleep(0.1) while process.read() != {'key': 'value3'}: time.sleep(0.1) process.stop()
def test_should_let_start_the_process_again_after_it_got_stopped(self): process = Process("./tests/models/output-echo.sh") process.start() while not process.running: time.sleep(0.1) process.stop() while process.running: time.sleep(0.1) process.start() while not process.running: time.sleep(0.1)
def __init__(self, command: str, parameters: Parameters): assert isinstance(command, str) assert isinstance(parameters, Parameters) self._command = command self._arguments = f"--id {parameters.id}" self._arguments += f" --flipper {parameters.flipper}" if parameters.flipper is not None else "" self._arguments += f" --flapper {parameters.flapper}" if parameters.flapper is not None else "" self._arguments += f" --flopper {parameters.flopper}" if parameters.flopper is not None else "" self._last_output = None self.logger.info(f"Instantiated model using process '{self._command} {self._arguments}'") self._process = Process(f"{self._command} {self._arguments}") self._process.start()
def test_should_read_multiple_json_documents(self): process = Process("./tests/models/output-multiple.sh") process.start() while process.read() != {'key': 'value1'}: time.sleep(0.1) while process.read() != {'key': 'value2'}: time.sleep(0.1) while process.read() != {'key': 'value3'}: time.sleep(0.1) process.stop() while process.running: time.sleep(0.1)
def __init__(self, command: str, parameters: Parameters): assert isinstance(command, str) assert isinstance(parameters, Parameters) self._command = command self._arguments = f"--id {parameters.id}" self._arguments += f" --collateral_auction_house {parameters.collateral_auction_house}" if parameters.collateral_auction_house is not None else "" self._arguments += f" --surplus_auction_house {parameters.surplus_auction_house}" if parameters.surplus_auction_house is not None else "" self._arguments += f" --debt_auction_house {parameters.debt_auction_house}" if parameters.debt_auction_house is not None else "" self._arguments += f" --staked_token_auction_house {parameters.staked_token_auction_house}" if parameters.staked_token_auction_house is not None else "" self._last_output = None self.logger.info( f"Instantiated model using process '{self._command} {self._arguments}'" ) self._process = Process(f"{self._command} {self._arguments}") self._process.start()
def __init__(self, command: str, parameters: Parameters): assert isinstance(command, str) assert isinstance(parameters, Parameters) self._command = command self._arguments = f"--id {parameters.id}" if isinstance(parameters.auction_contract, Clipper): self._arguments += f" --clipper {parameters.auction_contract.address}" elif isinstance(parameters.auction_contract, Flipper): self._arguments += f" --flipper {parameters.auction_contract.address}" elif isinstance(parameters.auction_contract, Flapper): self._arguments += f" --flapper {parameters.auction_contract.address}" elif isinstance(parameters.auction_contract, Flopper): self._arguments += f" --flopper {parameters.auction_contract.address}" self._last_output = None self.logger.info(f"Instantiated model using process '{self._command} {self._arguments}'") self._process = Process(f"{self._command} {self._arguments}") self._process.start()
def test_should_return_none_from_read_if_nothing_to_read(self): process = Process("./tests/models/terminate-voluntarily.sh") process.start() while process.running: assert process.read() is None
def test_should_not_let_start_the_process_twice(self): process = Process("./tests/models/output-echo.sh") process.start() with pytest.raises(Exception): process.start()