def test_header_oneline(): # edge case of a single header line fp = StringIO("""\ tags foo """) g = parse.parse_ticket(fp) next(g, 'tags/foo', '') assert_raises(StopIteration, g.next)
def test_empty(): fp = StringIO('') g = parse.parse_ticket(fp) e = assert_raises( parse.InvalidHeaderError, g.next, ) eq( str(e), 'Invalid header: Header had no complete lines', )
def test_continuation_emptyline_nowhitespace(): fp = StringIO("""\ nop -- one= \tbar """) g = parse.parse_ticket(fp) next(g, 'one', '\nbar\n') assert_raises(StopIteration, g.next)
def test_continuation(): fp = StringIO("""\ nop -- one= \tfoo \tbar """) g = parse.parse_ticket(fp) next(g, 'one', 'foo\nbar\n') assert_raises(StopIteration, g.next)
def test_bad_no_header_newline(): fp = StringIO("""\ I am the description. """) g = parse.parse_ticket(fp) e = assert_raises( parse.InvalidHeaderError, g.next, ) eq( str(e), 'Invalid header: Header had no complete lines', )
def test_bad_no_header(): fp = StringIO("""\ I am the description. """) g = parse.parse_ticket(fp) e = assert_raises( parse.InvalidHeaderError, g.next, ) eq( str(e), 'Invalid header: Line does not look like a header: %r' \ % 'I am the description.', )
def test_header_oneline_withdescription(): # edge case of a single header line fp = StringIO("""\ tags foo bar -- """) g = parse.parse_ticket(fp) next(g, 'tags/foo') next(g, 'description', """\ bar """) assert_raises(StopIteration, g.next)
def test_bad_continuation(): fp = StringIO("""\ \tfirst line!?! I am the description. """) g = parse.parse_ticket(fp) e = assert_raises( parse.InvalidHeaderError, g.next, ) eq( str(e), 'Invalid header: Cannot start with a continuation line: %r' \ % '\tfirst line!?!', )
def test_nontab_leadingspace(): fp = StringIO("""\ nop -- one= foo bar two= foo bar """) g = parse.parse_ticket(fp) next(g, 'one', 'foo\n bar\n') next(g, 'two', ' foo\nbar\n') assert_raises(StopIteration, g.next)
def test_no_variables(): fp = StringIO("""\ tags foo Frobbing is borked I ran frob and it was supposed to blarb, but it qwarked. """) g = parse.parse_ticket(fp) next(g, 'tags/foo') next(g, 'description', """\ Frobbing is borked I ran frob and it was supposed to blarb, but it qwarked. """) assert_raises(StopIteration, g.next)
def test_simple_separator(): fp = StringIO("""\ ticket d239371f3b6b61ca1076bb460e331b3edb412970 number #3431 tags priority:high denial-of-service security reporter:[email protected] seen build/301 Oncolator segfaults on some inputs The Oncolator service segfaults if I go to the web page, login, choose quick oncolation from the radio buttons and click the "Onc!" button. I need to demo this to the Board of Directors on Monday, need a fix quick! It crashed on me today around 9:20 am, you should be able to find it in the server logs. -- browser=Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.6) \tGecko/20061201 Firefox/2.0.0.6 (Ubuntu-feisty) """) g = parse.parse_ticket(fp) next(g, '_ticket', 'd239371f3b6b61ca1076bb460e331b3edb412970\n') next(g, 'number', '#3431\n') next(g, 'tags/priority:high') next(g, 'tags/denial-of-service') next(g, 'tags/security') next(g, 'tags/reporter:[email protected]') # TODO seen lookup! next(g, 'description', """\ Oncolator segfaults on some inputs The Oncolator service segfaults if I go to the web page, login, choose quick oncolation from the radio buttons and click the "Onc!" button. I need to demo this to the Board of Directors on Monday, need a fix quick! It crashed on me today around 9:20 am, you should be able to find it in the server logs. """) next(g, 'browser', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.6) Gecko/20061201 Firefox/2.0.0.6 (Ubuntu-feisty)\n') assert_raises(StopIteration, g.next)
def test_variables_blank_after_separator(): fp = StringIO("""\ tags foo Frobbing is borked I ran frob and it was supposed to blarb, but it qwarked. -- foo=bar """) g = parse.parse_ticket(fp) next(g, 'tags/foo') next(g, 'description', """\ Frobbing is borked I ran frob and it was supposed to blarb, but it qwarked. """) next(g, 'foo', 'bar\n') assert_raises(StopIteration, g.next)
def parse_file(filename): with file(filename) as f: for x in parse.parse_ticket(f): yield x os.unlink(filename)
) sys.exit(0) def parse_file(filename): with file(filename) as f: for x in parse.parse_ticket(f): yield x os.unlink(filename) content = parse_file(filename) # TODO leaves temp file lying around on errors, generators # make fixing that annoying # TODO abort if no semantic change? get rid of sha1 check else: content = parse.parse_ticket(sys.stdin) with storage.Transaction( repo='.', message="""\ Created ticket %s """ % ticket, ) as t: for variable, value in content: if variable == '_ticket': if value.strip() != ticket: # a different message based on whether we used # editor or not, just to make a bit more sense if sys.stdin.isatty(): print >>sys.stderr, \ '%s new: ticket identity must not be modified' % (