You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.2 KiB

  1. #!/usr/bin/env python3
  2. import json
  3. import os
  4. import sys
  5. if sys.version_info[0] >= 3:
  6. unicode = str
  7. trace_file = None
  8. expand = False
  9. for i in sys.argv[1:]:
  10. if trace_file is None and not i.startswith('-'):
  11. trace_file = i
  12. continue
  13. if i in ['-e', '--expand']:
  14. expand = True
  15. assert trace_file is not None
  16. assert os.path.exists(trace_file)
  17. if expand:
  18. msg_args = ['STATUS', 'fff', 'fff;sss; SPACES !!! ', ' 42 space in string!', ' SPACES !!! ']
  19. else:
  20. msg_args = ['STATUS', 'fff', '${ASDF}', ' ${FOO} ${BAR}', ' SPACES !!! ']
  21. required_traces = [
  22. {
  23. 'args': ['STATUS', 'JSON-V1 str', 'spaces'],
  24. 'cmd': 'message',
  25. },
  26. {
  27. 'args': ['ASDF', 'fff', 'sss', ' SPACES !!! '],
  28. 'cmd': 'set',
  29. },
  30. {
  31. 'args': ['FOO', '42'],
  32. 'cmd': 'set',
  33. },
  34. {
  35. 'args': ['BAR', ' space in string!'],
  36. 'cmd': 'set',
  37. },
  38. {
  39. 'args': msg_args,
  40. 'cmd': 'message',
  41. 'frame': 3 if expand else 2,
  42. 'global_frame': 3 if expand else 2
  43. },
  44. {
  45. 'args': ['STATUS', 'nested global_frame'],
  46. 'cmd': 'message',
  47. 'frame': 3,
  48. 'global_frame': 6 if expand else 5
  49. }
  50. ]
  51. with open(trace_file, 'r') as fp:
  52. # Check for version (must be the first document)
  53. vers = json.loads(fp.readline())
  54. assert sorted(vers.keys()) == ['version']
  55. assert sorted(vers['version'].keys()) == ['major', 'minor']
  56. assert vers['version']['major'] == 1
  57. assert vers['version']['minor'] == 2
  58. for i in fp.readlines():
  59. line = json.loads(i)
  60. assert sorted(line.keys()) == ['args', 'cmd', 'file', 'frame', 'global_frame','line', 'time']
  61. assert isinstance(line['args'], list)
  62. assert isinstance(line['cmd'], unicode)
  63. assert isinstance(line['file'], unicode)
  64. assert isinstance(line['frame'], int)
  65. assert isinstance(line['global_frame'], int)
  66. assert isinstance(line['line'], int)
  67. assert isinstance(line['time'], float)
  68. for j in required_traces:
  69. # Compare the subset of required keys with line
  70. if {k: line[k] for k in j} == j:
  71. required_traces.remove(j)
  72. assert not required_traces