mirror of
https://github.com/mnaberez/py65.git
synced 2025-01-16 03:30:01 +00:00
Strip trailing whitespace
This commit is contained in:
parent
0c51e9f337
commit
e8565a6e81
@ -11,10 +11,10 @@ class ObservableMemoryTests(unittest.TestCase):
|
||||
def test___setitem__with_no_listeners_changes_memory(self):
|
||||
subject = self._make_subject()
|
||||
mem = ObservableMemory(subject=subject)
|
||||
|
||||
|
||||
mem[0xC000] = 0xAB
|
||||
self.assertEqual(0xAB, subject[0xC000])
|
||||
|
||||
|
||||
def test___setitem__ignores_subscribers_returning_none(self):
|
||||
subject = self._make_subject()
|
||||
mem = ObservableMemory(subject=subject)
|
||||
@ -24,131 +24,131 @@ class ObservableMemoryTests(unittest.TestCase):
|
||||
|
||||
def write_subscriber_2(address, value):
|
||||
return None
|
||||
|
||||
|
||||
mem.subscribe_to_write([0xC000], write_subscriber_1)
|
||||
mem.subscribe_to_write([0xC000], write_subscriber_2)
|
||||
|
||||
|
||||
mem[0xC000] = 0xAB
|
||||
self.assertEqual(0xAB, subject[0xC000])
|
||||
|
||||
def test___setitem__uses_result_of_last_subscriber(self):
|
||||
subject = self._make_subject()
|
||||
mem = ObservableMemory(subject=subject)
|
||||
|
||||
|
||||
def write_subscriber_1(address, value):
|
||||
return 0x01
|
||||
|
||||
|
||||
def write_subscriber_2(address, value):
|
||||
return 0x02
|
||||
|
||||
|
||||
mem.subscribe_to_write([0xC000], write_subscriber_1)
|
||||
mem.subscribe_to_write([0xC000], write_subscriber_2)
|
||||
|
||||
|
||||
mem[0xC000] = 0xAB
|
||||
self.assertEqual(0x02, subject[0xC000])
|
||||
|
||||
|
||||
# subscribe_to_read
|
||||
|
||||
|
||||
def test_subscribe_to_read_covers_all_addresses_in_range(self):
|
||||
subject = self._make_subject()
|
||||
mem = ObservableMemory(subject=subject)
|
||||
|
||||
|
||||
def read_subscriber(address, value):
|
||||
return 0xAB
|
||||
|
||||
|
||||
mem.subscribe_to_read(xrange(0xC000, 0xC001+1), read_subscriber)
|
||||
|
||||
|
||||
mem[0xC000] = 0xAB
|
||||
mem[0xC001] = 0xAB
|
||||
self.assertEqual(0xAB, subject[0xC001])
|
||||
self.assertEqual(0xAB, subject[0xC001])
|
||||
|
||||
|
||||
def test__subscribe_to_read_does_not_register_same_listener_twice(self):
|
||||
subject = self._make_subject()
|
||||
mem = ObservableMemory(subject=subject)
|
||||
|
||||
|
||||
calls = []
|
||||
def read_subscriber(address):
|
||||
calls.append('read_subscriber')
|
||||
|
||||
|
||||
mem.subscribe_to_read([0xC000], read_subscriber)
|
||||
mem.subscribe_to_read([0xC000], read_subscriber)
|
||||
|
||||
|
||||
value = mem[0xC000]
|
||||
self.assertEqual(['read_subscriber'], calls)
|
||||
|
||||
|
||||
# __getitem__
|
||||
|
||||
|
||||
def test___getitem__with_no_write_subscribers_changes_memory(self):
|
||||
subject = self._make_subject()
|
||||
mem = ObservableMemory(subject=subject)
|
||||
|
||||
|
||||
subject[0xC000] = 0xAB
|
||||
self.assertEqual(0xAB, mem[0xC000])
|
||||
|
||||
|
||||
def test___getitem__ignores_read_subscribers_returning_none(self):
|
||||
subject = self._make_subject()
|
||||
mem = ObservableMemory(subject=subject)
|
||||
|
||||
|
||||
def read_subscriber_1(address):
|
||||
return None
|
||||
|
||||
|
||||
def read_subscriber_2(address):
|
||||
return None
|
||||
|
||||
|
||||
mem.subscribe_to_read([0xC000], read_subscriber_1)
|
||||
mem.subscribe_to_read([0xC000], read_subscriber_2)
|
||||
|
||||
|
||||
mem[0xC000] = 0xAB
|
||||
self.assertEqual(0xAB, subject[0xC000])
|
||||
|
||||
|
||||
def test___getitem__calls_all_read_subscribers_uses_last_result(self):
|
||||
subject = self._make_subject()
|
||||
mem = ObservableMemory(subject=subject)
|
||||
|
||||
|
||||
calls = []
|
||||
def read_subscriber_1(address):
|
||||
calls.append('read_subscriber_1')
|
||||
return 0x01
|
||||
|
||||
|
||||
def read_subscriber_2(address):
|
||||
calls.append('read_subscriber_2')
|
||||
return 0x02
|
||||
|
||||
|
||||
mem.subscribe_to_read([0xC000], read_subscriber_1)
|
||||
mem.subscribe_to_read([0xC000], read_subscriber_2)
|
||||
|
||||
|
||||
subject[0xC000] = 0xAB
|
||||
self.assertEqual(0x02, mem[0xC000])
|
||||
|
||||
expected_calls = ['read_subscriber_1', 'read_subscriber_2']
|
||||
self.assertEqual(expected_calls, calls)
|
||||
|
||||
|
||||
# __getattr__
|
||||
|
||||
|
||||
def test__getattr__proxies_subject(self):
|
||||
subject = self._make_subject()
|
||||
mem = ObservableMemory(subject=subject)
|
||||
self.assertEqual(subject.count, mem.count)
|
||||
|
||||
|
||||
# write
|
||||
|
||||
|
||||
def test_write_directly_writes_values_to_subject(self):
|
||||
subject = self._make_subject()
|
||||
mem = ObservableMemory(subject=subject)
|
||||
|
||||
|
||||
def write_subscriber(address, value):
|
||||
return 0xFF
|
||||
mem.subscribe_to_write([0xC000,0xC001], write_subscriber)
|
||||
|
||||
|
||||
mem.write(0xC000, [0x01, 002])
|
||||
self.assertEqual(0x01, subject[0xC000])
|
||||
self.assertEqual(0x02, subject[0xC001])
|
||||
|
||||
# Test Helpers
|
||||
|
||||
def _make_subject(self):
|
||||
subject = 0x10000 * [0x00]
|
||||
|
||||
def _make_subject(self):
|
||||
subject = 0x10000 * [0x00]
|
||||
return subject
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -20,8 +20,8 @@ class HexdumpLoaderTests(unittest.TestCase):
|
||||
text = " \r\n \t \n"
|
||||
loader = Loader(text)
|
||||
self.assertEqual(None, loader.start_address)
|
||||
self.assertEqual([], loader.data)
|
||||
|
||||
self.assertEqual([], loader.data)
|
||||
|
||||
def test_raises_when_start_address_not_found(self):
|
||||
text = 'aa bb cc'
|
||||
try:
|
||||
@ -36,7 +36,7 @@ class HexdumpLoaderTests(unittest.TestCase):
|
||||
try:
|
||||
Loader(text)
|
||||
self.fail()
|
||||
except ValueError, why:
|
||||
except ValueError, why:
|
||||
msg = 'Could not parse address: oops'
|
||||
self.assertEqual(msg, why[0])
|
||||
|
||||
@ -45,7 +45,7 @@ class HexdumpLoaderTests(unittest.TestCase):
|
||||
try:
|
||||
Loader(text)
|
||||
self.fail()
|
||||
except ValueError, why:
|
||||
except ValueError, why:
|
||||
msg = 'Expected address to be 2 bytes, got 1'
|
||||
self.assertEqual(msg, why[0])
|
||||
|
||||
@ -54,7 +54,7 @@ class HexdumpLoaderTests(unittest.TestCase):
|
||||
try:
|
||||
Loader(text)
|
||||
self.fail()
|
||||
except ValueError, why:
|
||||
except ValueError, why:
|
||||
msg = 'Expected address to be 2 bytes, got 3'
|
||||
self.assertEqual(msg, why[0])
|
||||
|
||||
@ -67,7 +67,7 @@ class HexdumpLoaderTests(unittest.TestCase):
|
||||
msg = 'Non-contigous block detected. Expected next ' \
|
||||
'address to be $c001, label was $c002'
|
||||
self.assertEqual(msg, why[0])
|
||||
|
||||
|
||||
def test_raises_when_data_is_invalid(self):
|
||||
text = 'c000: foo'
|
||||
try:
|
||||
@ -75,7 +75,7 @@ class HexdumpLoaderTests(unittest.TestCase):
|
||||
self.fail()
|
||||
except ValueError, why:
|
||||
msg = 'Could not parse data: foo'
|
||||
self.assertEqual(msg, why[0])
|
||||
self.assertEqual(msg, why[0])
|
||||
|
||||
def test_loads_data_without_dollar_signs(self):
|
||||
text = 'c000: aa bb'
|
||||
@ -100,32 +100,32 @@ class HexdumpLoaderTests(unittest.TestCase):
|
||||
load = Loader(text)
|
||||
self.assertEqual(0xC000, load.start_address)
|
||||
self.assertEqual([0xAA, 0xBB, 0xCC], load.data)
|
||||
|
||||
|
||||
def test_ignores_semicolon_comments(self):
|
||||
text = 'c000: aa bb ;comment'
|
||||
load = Loader(text)
|
||||
self.assertEqual(0xC000, load.start_address)
|
||||
self.assertEqual([0xAA, 0xBB], load.data)
|
||||
|
||||
|
||||
def test_ignores_double_dash_comments(self):
|
||||
text = 'c000: aa bb -- comment'
|
||||
load = Loader(text)
|
||||
self.assertEqual(0xC000, load.start_address)
|
||||
self.assertEqual([0xAA, 0xBB], load.data)
|
||||
|
||||
|
||||
def test_ignores_pound_comments(self):
|
||||
text = 'c000: aa bb # comment'
|
||||
load = Loader(text)
|
||||
self.assertEqual(0xC000, load.start_address)
|
||||
self.assertEqual([0xAA, 0xBB], load.data)
|
||||
|
||||
|
||||
def test_ignores_pound_comments(self):
|
||||
text = 'c000: aa bb # comment'
|
||||
load = Loader(text)
|
||||
self.assertEqual(0xC000, load.start_address)
|
||||
self.assertEqual([0xAA, 0xBB], load.data)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def test_suite():
|
||||
return unittest.findTestCases(sys.modules[__name__])
|
||||
|
@ -5,7 +5,7 @@ if sys.platform[:3] == "win":
|
||||
|
||||
def getch(stdin):
|
||||
""" Read one character from the Windows console, blocking until one
|
||||
is available. Does not echo the character. The stdin argument is
|
||||
is available. Does not echo the character. The stdin argument is
|
||||
for function signature compatibility and is ignored.
|
||||
"""
|
||||
return msvcrt.getch()
|
||||
@ -27,7 +27,7 @@ else:
|
||||
|
||||
def getch(stdin):
|
||||
""" Read one character from stdin, blocking until one is available.
|
||||
Does not echo the character.
|
||||
Does not echo the character.
|
||||
"""
|
||||
fd = stdin.fileno()
|
||||
oldattr = termios.tcgetattr(fd)
|
||||
@ -41,10 +41,10 @@ else:
|
||||
return char
|
||||
|
||||
def getch_noblock(stdin):
|
||||
""" Read one character from stdin without blocking. Does not echo the
|
||||
""" Read one character from stdin without blocking. Does not echo the
|
||||
character. If no character is available, an empty string is returned.
|
||||
"""
|
||||
|
||||
|
||||
fd = stdin.fileno()
|
||||
|
||||
oldterm = termios.tcgetattr(fd)
|
||||
@ -61,7 +61,7 @@ else:
|
||||
if r:
|
||||
char = stdin.read(1)
|
||||
if char == "\n":
|
||||
char = "\r"
|
||||
char = "\r"
|
||||
else:
|
||||
char = ''
|
||||
finally:
|
||||
@ -71,7 +71,7 @@ else:
|
||||
|
||||
|
||||
def line_input(prompt='', stdin=sys.stdin, stdout=sys.stdout):
|
||||
""" Read a line from stdin, printing each character as it is typed.
|
||||
""" Read a line from stdin, printing each character as it is typed.
|
||||
Does not echo a newline at the end. This allows the calling program
|
||||
to overwrite the line by first sending a carriage return ('\r'), which
|
||||
is useful in modes like the interactive assembler.
|
||||
@ -82,7 +82,7 @@ def line_input(prompt='', stdin=sys.stdin, stdout=sys.stdout):
|
||||
char = getch(stdin)
|
||||
code = ord(char)
|
||||
if char in ("\n", "\r"):
|
||||
break
|
||||
break
|
||||
elif code in (0x7f, 0x08): # backspace
|
||||
if len(line) > 0:
|
||||
line = line[:-1]
|
||||
@ -90,8 +90,7 @@ def line_input(prompt='', stdin=sys.stdin, stdout=sys.stdout):
|
||||
(' ' * (len(prompt+line) +5), prompt, line))
|
||||
elif code == 0x1b: # escape
|
||||
pass
|
||||
else:
|
||||
else:
|
||||
line += char
|
||||
stdout.write(char)
|
||||
return line
|
||||
|
@ -12,7 +12,7 @@ def itoa(num, base=10):
|
||||
if negative:
|
||||
digits.append('-')
|
||||
digits.reverse()
|
||||
return ''.join(digits)
|
||||
return ''.join(digits)
|
||||
|
||||
def convert_to_bin(bcd):
|
||||
return bcd2bin[bcd]
|
||||
|
@ -13,7 +13,7 @@ class Loader:
|
||||
|
||||
for line in text.splitlines():
|
||||
self._parse_line(line)
|
||||
|
||||
|
||||
def _reset(self):
|
||||
self.data = []
|
||||
self.start_address = None
|
||||
@ -25,8 +25,8 @@ class Loader:
|
||||
|
||||
for piece in pieces:
|
||||
if piece.startswith('$'):
|
||||
piece = piece[1:]
|
||||
|
||||
piece = piece[1:]
|
||||
|
||||
if piece.endswith(':'):
|
||||
self._parse_address(piece[:-1])
|
||||
|
||||
@ -43,7 +43,7 @@ class Loader:
|
||||
def _parse_address(self, piece):
|
||||
try:
|
||||
addr_bytes = [ ord(c) for c in a2b_hex(piece) ]
|
||||
except (TypeError, ValueError):
|
||||
except (TypeError, ValueError):
|
||||
msg = "Could not parse address: %s" % piece
|
||||
raise ValueError, msg
|
||||
|
||||
@ -58,9 +58,9 @@ class Loader:
|
||||
self.start_address = address
|
||||
self.current_address = address
|
||||
|
||||
elif address != (self.current_address):
|
||||
elif address != (self.current_address):
|
||||
msg = "Non-contigous block detected. Expected next address " \
|
||||
"to be $%04x, label was $%04x" % (self.current_address,
|
||||
"to be $%04x, label was $%04x" % (self.current_address,
|
||||
address)
|
||||
raise ValueError, msg
|
||||
|
||||
@ -71,7 +71,7 @@ class Loader:
|
||||
|
||||
else:
|
||||
try:
|
||||
bytes = [ ord(c) for c in a2b_hex(piece) ]
|
||||
bytes = [ ord(c) for c in a2b_hex(piece) ]
|
||||
except (TypeError, ValueError):
|
||||
msg = "Could not parse data: %s" % piece
|
||||
raise ValueError, msg
|
||||
|
Loading…
x
Reference in New Issue
Block a user