def test_1010(self, cn_client_v2): """preloop(): Successful deinitialization""" cli = d1_cli.impl.cli.CLI() cli.preloop() with d1_test.d1_test_case.capture_std() as (out_stream, err_stream): cli.postloop() assert 'Exiting' in out_stream.getvalue()
def test_1020(self, cn_client_v2): """precmd(): Successful line formattting""" cli = d1_cli.impl.cli.CLI() cli.preloop() test_cmd_str = 'somecommand arg1 arg2 arg3' received_line = cli.precmd(test_cmd_str) assert test_cmd_str in received_line
def test_1100(self, cn_client_v2): """do_eof(): Calls sys.exit()""" cli = d1_cli.impl.cli.CLI() cli.preloop() with mock.patch('sys.exit', return_value='') as mock_method: cli.do_eof('') assert mock_method.call_count > 0
def test_1060(self, cn_client_v2): """do_history(): Returns history""" cli = d1_cli.impl.cli.CLI() cli.preloop() test_cmd_str = 'somecommand1 arg1 arg2 arg3' cli.precmd(test_cmd_str) test_cmd_str = 'somecommand2 arg1 arg2 arg3' cli.precmd(test_cmd_str) with d1_test.d1_test_case.capture_std() as (out_stream, err_stream): cli.do_history('') assert 'somecommand1' in out_stream.getvalue() assert 'somecommand2' in out_stream.getvalue()
def _do_exit(self, answer_str, exit_call_count): """do_exit(): Gives option to cancel if the operation queue is not empty""" cli = d1_cli.impl.cli.CLI() cli.preloop() fi, tmp_path = tempfile.mkstemp(prefix='test_dataone_cli.', suffix='.tmp', text=True) os.close(fi) cli.do_set('authoritative-mn urn:node:myTestMN') cli.do_set('rights-holder test-rights-holder-subject') create_operation = cli._command_processor._operation_maker.create( 'test_pid', tmp_path, 'test_format_id') cli._command_processor._operation_queue.append(create_operation) with d1_test.d1_test_case.capture_std() as (out_stream, err_stream): with d1_test.d1_test_case.mock_input(answer_str): with mock.patch('sys.exit', return_value='') as mock_method: cli.do_exit('') assert mock_method.call_count == exit_call_count assert 'There are 1 unperformed operations in the write operation queue' in out_stream.getvalue( )
def test_1110(self, cn_client_v2): """do_reset(), do_set(), do_save(), do_load(): Session to disk round trip""" cli = d1_cli.impl.cli.CLI() cli.preloop() fi, path = tempfile.mkstemp(prefix='test_dataone_cli.', suffix='.tmp', text=True) os.close(fi) # Reset, set some values and save to file cli.do_reset('') cli.do_set('editor test_editor') cli.do_set('cn-url test_cn-url') cli.do_set('key-file test-key-file') cli.do_save(path) # Reset and check that values are at their defaults cli.do_reset('') with d1_test.d1_test_case.capture_std() as (out_stream, err_stream): cli.do_set('editor') assert 'editor: nano' in out_stream.getvalue() with d1_test.d1_test_case.capture_std() as (out_stream, err_stream): cli.do_set('cn-url') assert 'cn-url: https://cn.dataone.org/cn' in out_stream.getvalue() with d1_test.d1_test_case.capture_std() as (out_stream, err_stream): cli.do_set('key-file') assert 'key-file: None' in out_stream.getvalue() # Load from file and verify cli.do_load(path) with d1_test.d1_test_case.capture_std() as (out_stream, err_stream): cli.do_set('editor') assert 'editor: test_editor' in out_stream.getvalue() with d1_test.d1_test_case.capture_std() as (out_stream, err_stream): cli.do_set('cn-url') assert 'cn-url: test_cn-url' in out_stream.getvalue() with d1_test.d1_test_case.capture_std() as (out_stream, err_stream): cli.do_set('key-file') assert 'key-file: test-key-file' in out_stream.getvalue()
def test_1000(self, cn_client_v2): """preloop(): Successful initialization""" cli = d1_cli.impl.cli.CLI() cli.preloop()