2018-03-01 03:05:12 +00:00
|
|
|
from uncompyle6.scanners.tok import Token
|
|
|
|
|
2020-01-22 09:49:44 +00:00
|
|
|
|
2018-03-01 03:05:12 +00:00
|
|
|
def test_token():
|
|
|
|
# Test token formatting of: LOAD_CONST None
|
2020-01-22 09:49:44 +00:00
|
|
|
t = Token("LOAD_CONST", offset=0, attr=None, pattr=None, has_arg=True)
|
2020-04-04 14:26:46 +00:00
|
|
|
expect = "0 LOAD_CONST None"
|
2018-03-01 03:05:12 +00:00
|
|
|
# print(t.format())
|
|
|
|
assert t
|
2020-04-04 14:26:46 +00:00
|
|
|
assert t.format().strip() == expect.strip()
|
2018-03-01 03:05:12 +00:00
|
|
|
|
|
|
|
# Make sure equality testing of tokens ignores offset
|
2020-01-22 09:49:44 +00:00
|
|
|
t2 = Token("LOAD_CONST", offset=2, attr=None, pattr=None, has_arg=True)
|
2018-03-01 03:05:12 +00:00
|
|
|
assert t2 == t
|
|
|
|
|
|
|
|
# Make sure formatting of: LOAD_CONST False. We assume False is the 0th index
|
|
|
|
# of co_consts.
|
2020-01-22 09:49:44 +00:00
|
|
|
t = Token("LOAD_CONST", offset=1, attr=False, pattr=False, has_arg=True)
|
2020-04-04 14:26:46 +00:00
|
|
|
expect = "1 LOAD_CONST False"
|
|
|
|
assert t.format().strip() == expect.strip()
|
2018-03-01 22:23:58 +00:00
|
|
|
|
2020-01-22 09:49:44 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2018-03-01 22:23:58 +00:00
|
|
|
test_token()
|