1
0
mirror of https://github.com/mnaberez/py65.git synced 2024-06-06 20:29:34 +00:00

Fix tests using temporary files on Windows

This commit is contained in:
Mike Naberezny 2021-12-26 16:24:53 -08:00
parent d86398e8f9
commit 72df56db53

View File

@ -1184,18 +1184,21 @@ class MonitorTests(unittest.TestCase):
self.assertEqual(0xc002, mon._mpu.pc)
def test_argv_load(self):
with tempfile.NamedTemporaryFile('wb+') as f:
try:
with tempfile.NamedTemporaryFile('wb+', delete=False) as f:
data = bytearray([0xab, 0xcd])
f.write(data)
f.flush()
argv = ['py65mon', '--load', f.name]
stdout = StringIO()
mon = Monitor(argv=argv, stdout=stdout)
self.assertEqual(list(data), mon._mpu.memory[:len(data)])
finally:
os.unlink(f.name)
def test_argv_rom(self):
with tempfile.NamedTemporaryFile('wb+') as f:
try:
with tempfile.NamedTemporaryFile('wb+', delete=False) as f:
rom = bytearray(4096)
rom[0] = 0xea # f000 nop
rom[1] = 0xea # f001 nop
@ -1203,13 +1206,14 @@ class MonitorTests(unittest.TestCase):
rom[-2] = 0xf000 & 0xff # fffc reset vector low
rom[-3] = 0xf000 >> 8 # fffd reset vector high
f.write(rom)
f.flush()
argv = ['py65mon', '--rom', f.name]
stdout = StringIO()
mon = Monitor(argv=argv, stdout=stdout)
self.assertEqual(list(rom), mon._mpu.memory[-len(rom):])
self.assertEqual(0xf002, mon._mpu.pc)
finally:
os.unlink(f.name)
def test_argv_input(self):
argv = ['py65mon', '--input', 'abcd']
@ -1228,7 +1232,8 @@ class MonitorTests(unittest.TestCase):
self.assertTrue('putc' in repr(write_subscribers[0xdcba]))
def test_argv_combination_rom_mpu(self):
with tempfile.NamedTemporaryFile('wb+') as f:
try:
with tempfile.NamedTemporaryFile('wb+', delete=False) as f:
rom = bytearray(4096)
rom[0] = 0xea # f000 nop
rom[1] = 0xea # f001 nop
@ -1236,7 +1241,6 @@ class MonitorTests(unittest.TestCase):
rom[-2] = 0xf000 & 0xff # fffc reset vector low
rom[-3] = 0xf000 >> 8 # fffd reset vector high
f.write(rom)
f.flush()
argv = ['py65mon', '--rom', f.name, '--mpu', '65c02',]
stdout = StringIO()
@ -1244,6 +1248,8 @@ class MonitorTests(unittest.TestCase):
self.assertEqual('65C02', mon._mpu.name)
self.assertEqual(list(rom), mon._mpu.memory[-len(rom):])
self.assertEqual(0xf002, mon._mpu.pc)
finally:
os.unlink(f.name)
def test_suite():
return unittest.findTestCases(sys.modules[__name__])