def test_json_constructs(): """This tests some of the internal JSON stuff so we don't break zamboni.""" e = ErrorBundle() e.detected_type = 1 e.error(('a', 'b', 'c'), 'Test') e.error(('a', 'b', 'foo'), 'Test') e.error(('a', 'foo', 'c'), 'Test') e.error(('a', 'foo', 'c'), 'Test') e.error(('b', 'foo', 'bar'), 'Test') e.warning((), 'Context test', context=('x', 'y', 'z')) e.warning((), 'Context test', context=ContextGenerator('x\ny\nz\n'), line=2, column=0) e.notice((), 'none') e.notice((), 'line', line=1) e.notice((), 'column', column=0) e.notice((), 'line column', line=1, column=1) results = e.render_json() print results j = json.loads(results) assert 'detected_type' in j assert j['detected_type'] == 'extension' assert 'message_tree' in j tree = j['message_tree'] assert '__errors' not in tree assert not tree['a']['__messages'] assert tree['a']['__errors'] == 4 assert not tree['a']['b']['__messages'] assert tree['a']['b']['__errors'] == 2 assert not tree['a']['b']['__messages'] assert tree['a']['b']['c']['__errors'] == 1 assert tree['a']['b']['c']['__messages'] assert 'messages' in j for m in (m for m in j['messages'] if m['type'] == 'warning'): assert m['context'] == ['x', 'y', 'z'] for m in (m for m in j['messages'] if m['type'] == 'notice'): if 'line' in m['message']: assert m['line'] is not None assert isinstance(m['line'], int) assert m['line'] > 0 else: assert m['line'] is None if 'column' in m['message']: assert m['column'] is not None assert isinstance(m['column'], int) assert m['column'] > -1 else: assert m['column'] is None
def run(data, expectation, line=2): # Strip blank lines. data = '\n'.join(filter(None, data.split('\n'))) # Get the context and assert its equality. c = ContextGenerator(data) eq_(c.get_context(line), expectation)