def test_tap_file(self): data = [1, 2, 4] tap_data = create_tap_header_block('test_tap', 32768, len(data)) tap_data.extend(create_tap_data_block(data)) tap_data.extend(create_tap_header_block('numbers', data_type=1)) tap_data.extend(create_tap_data_block([8, 16, 32])) tapfile = self.write_bin_file(tap_data, suffix='.tap') output, error = self.run_tapinfo(tapfile) self.assertEqual(len(error), 0) exp_output = [ '1:', ' Type: Header block', ' Bytes: test_tap', ' CODE: 32768,3', ' Length: 19', ' Data: 0, 3, 116, 101, 115, 116, 95 ... 3, 0, 0, 128, 0, 0, 172', '2:', ' Type: Data block', ' Length: 5', ' Data: 255, 1, 2, 4, 7', '3:', ' Type: Header block', ' Number array: numbers', ' Length: 19', ' Data: 0, 1, 110, 117, 109, 98, 101 ... 0, 0, 0, 0, 0, 0, 81', '4:', ' Type: Data block', ' Length: 5', ' Data: 255, 8, 16, 32, 56' ] self.assertEqual(exp_output, output)
def test_tap_file(self): data = [1, 2, 4] tap_data = create_tap_header_block('test_tap01', 32768, len(data)) tap_data.extend(create_tap_data_block(data)) tap_data.extend(create_tap_header_block('numbers_01', data_type=1)) tap_data.extend(create_tap_data_block([8, 16, 32])) tapfile = self.write_bin_file(tap_data, suffix='.tap') output, error = self.run_tapinfo(tapfile) self.assertEqual(error, '') exp_output = """ 1: Type: Header block Bytes: test_tap01 CODE: 32768,3 Length: 19 Data: 0, 3, 116, 101, 115, 116, 95 ... 3, 0, 0, 128, 0, 0, 173 2: Type: Data block Length: 5 Data: 255, 1, 2, 4, 7 3: Type: Header block Number array: numbers_01 Length: 19 Data: 0, 1, 110, 117, 109, 98, 101 ... 0, 0, 0, 0, 0, 0, 47 4: Type: Data block Length: 5 Data: 255, 8, 16, 32, 56 """ self.assertEqual(dedent(exp_output).lstrip(), output)
def test_tap_file(self): data = [1, 2, 4] tap_data = create_tap_header_block("test_tap", 32768, len(data)) tap_data.extend(create_tap_data_block(data)) tap_data.extend(create_tap_header_block("numbers", data_type=1)) tap_data.extend(create_tap_data_block([8, 16, 32])) tapfile = self.write_bin_file(tap_data, suffix=".tap") output, error = self.run_tapinfo(tapfile) self.assertEqual(len(error), 0) exp_output = [ "1:", " Type: Header block", " Bytes: test_tap", " CODE: 32768,3", " Length: 19", " Data: 0, 3, 116, 101, 115, 116, 95 ... 3, 0, 0, 128, 0, 0, 172", "2:", " Type: Data block", " Length: 5", " Data: 255, 1, 2, 4, 7", "3:", " Type: Header block", " Number array: numbers", " Length: 19", " Data: 0, 1, 110, 117, 109, 98, 101 ... 0, 0, 0, 0, 0, 0, 81", "4:", " Type: Data block", " Length: 5", " Data: 255, 8, 16, 32, 56", ] self.assertEqual(exp_output, output)
def test_standard_load_from_tap_file(self): basic_data = [1, 2, 3] code_start = 32768 code = [4, 5] blocks = [ create_tap_header_block(data_type=0), create_tap_data_block(basic_data), create_tap_header_block(start=code_start), create_tap_data_block(code) ] tapfile = self._write_tap(blocks) z80file = self.write_bin_file(suffix='.z80') output, error = self.run_tap2sna('--force {} {}'.format(tapfile, z80file)) self.assertEqual(error, '') snapshot = get_snapshot(z80file) self.assertEqual(basic_data, snapshot[23755:23755 + len(basic_data)]) self.assertEqual(code, snapshot[code_start:code_start + len(code)])
def test_standard_load_with_unknown_block_type(self): block_type = 1 # Array of numbers blocks = [ create_tap_header_block(data_type=block_type), create_tap_data_block([1]) ] tapfile = self._write_tap(blocks) z80file = self.write_bin_file(suffix='.z80') with self.assertRaises(SkoolKitError) as cm: self.run_tap2sna('--force {} {}'.format(tapfile, z80file)) self.assertEqual(cm.exception.args[0], 'Error while getting snapshot {}: Unknown block type ({}) in header block 1'.format(z80file, block_type))
def test_option_d_with_tap_file(self): data = [1, 2, 4, 8] tap_data = create_tap_header_block('test_tap02', 49152, len(data)) tap_data.extend(create_tap_data_block(data)) tap_data.extend(create_tap_header_block('characters', data_type=2)) tap_data.extend(create_tap_data_block(list(range(32, 94)))) tapfile = self.write_bin_file(tap_data, suffix='.tap') output, error = self.run_tapinfo('-d {}'.format(tapfile)) self.assertEqual(error, '') exp_output = """ 1: Type: Header block Bytes: test_tap02 CODE: 49152,4 Length: 19 0000 00 03 74 65 73 74 5F 74 61 70 30 32 04 00 00 C0 ..test_tap02.... 0010 00 00 E9 ... 2: Type: Data block Length: 6 0000 FF 01 02 04 08 0F ...... 3: Type: Header block Character array: characters Length: 19 0000 00 02 63 68 61 72 61 63 74 65 72 73 00 00 00 00 ..characters.... 0010 00 00 08 ... 4: Type: Data block Length: 64 0000 FF 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E . !"#$%&'()*+,-. 0010 2F 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E /0123456789:;<=> 0020 3F 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E ?@ABCDEFGHIJKLMN 0030 4F 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 01 OPQRSTUVWXYZ[\]. """ self.assertEqual(dedent(exp_output).lstrip(), output)
def test_standard_load_ignores_truncated_header_block(self): code_start = 30000 code = [2, 3, 4] length = len(code) blocks = [ create_tap_header_block(start=code_start)[:-1], create_tap_data_block(code), ] tapfile = self._write_tap(blocks) z80file = self.write_bin_file(suffix='.z80') output, error = self.run_tap2sna('--force {} {}'.format(tapfile, z80file)) self.assertEqual(error, '') snapshot = get_snapshot(z80file) self.assertEqual([0] * length, snapshot[code_start:code_start + length])
def test_standard_load_ignores_headerless_block(self): code_start = 16384 code = [2] blocks = [ create_tap_header_block(start=code_start), create_tap_data_block(code), create_tap_data_block([23]) ] tapfile = self._write_tap(blocks) z80file = self.write_bin_file(suffix='.z80') output, error = self.run_tap2sna('--force {} {}'.format(tapfile, z80file)) self.assertEqual(error, '') snapshot = get_snapshot(z80file) self.assertEqual(code, snapshot[code_start:code_start + len(code)])