def test_debug_mode_write(): result_out = StringIO() result_serial = BytesIO() test_input = "test/testB.rom" main(result_out, [ "", "-w", "-x", "-s", "0", "-e", "16", "-p", result_serial, test_input ]) print("OUT:", result_out.getvalue()) assert result_out.getvalue() == """ROM file is 32 bytes long. Writing ROM test/testB.rom to EEPROM. """ print("SERIAL:", result_serial.getvalue()) assert result_serial.getvalue( ) == b'W0000:42424242424242424242424242424242,00\n'
def test_debug_mode_dump(): result_out = StringIO() result_serial = BytesIO() main(result_out, [ "", "-x", "-s", "0", "-e", "15", "-d", "-p", result_serial, "/tmp/foo" ]) print("OUT:", result_out.getvalue()) assert result_out.getvalue() == """Writing contents to /tmp/foo Reading EEPROM from 0 to 15 Dumping to file. bytes written:16 """ print("SERIAL:", result_serial.getvalue()) assert result_serial.getvalue() == b'R0000\n'
def test_main_arg_parsing_options_right_sizes(): result = StringIO() with pytest.raises(SystemExit) as err: main(result, ["", "-S", "1", "-s", "0", "-e", "2048"]) assert result.getvalue( ) == "Address range is bigger than EEPROM size.\n" + usage_string
def test_main_arg_parsing_options(): result = StringIO() with pytest.raises(SystemExit) as err: main(result, ["", "-r", "-V"]) assert result.getvalue() == "No serial device attached.\n"
def test_main_arg_parsing_options_dump_file_required(): result = StringIO() with pytest.raises(SystemExit) as err: main(result, ["", "-d"]) assert result.getvalue( ) == "Must provide ROM file name to dump to.\n" + usage_string
def test_main_arg_parsing_options_verify_file_required(): result = StringIO() with pytest.raises(SystemExit) as err: main(result, ["", "-v"]) assert result.getvalue( ) == "Must provide ROM file to verify against.\n" + usage_string
def test_main_arg_parsing_options_verify_dump_conflict(): result = StringIO() with pytest.raises(SystemExit) as err: main(result, ["", "-d", "-v", "-s", "0", "-e", "15", "test/testC.rom"]) assert result.getvalue( ) == "Can't verify AND dump to file...choose one or other.\n" + usage_string
def test_main_arg_parsing_romsize(): result = StringIO() with pytest.raises(SystemExit) as err: main(result, ["", "-S", "33"]) assert result.getvalue() == "33 is not a valid ROMSIZE\n" + usage_string
def test_main_arg_parsing_valid_args(): result = StringIO() with pytest.raises(SystemExit) as err: main(result, ["", "-?"]) print(result.getvalue()) assert result.getvalue() == "option -? not recognized\n" + usage_string