| 4 | | from yaml.reader import Mark |
| | 4 | def test_marks(marks_filename, verbose=False): |
| | 5 | inputs = open(marks_filename, 'rb').read().split('---\n')[1:] |
| | 6 | for input in inputs: |
| | 7 | index = 0 |
| | 8 | line = 0 |
| | 9 | column = 0 |
| | 10 | while input[index] != '*': |
| | 11 | if input[index] == '\n': |
| | 12 | line += 1 |
| | 13 | column = 0 |
| | 14 | else: |
| | 15 | column += 1 |
| | 16 | index += 1 |
| | 17 | mark = yaml.Mark(marks_filename, index, line, column, unicode(input), index) |
| | 18 | snippet = mark.get_snippet(indent=2, max_length=79) |
| | 19 | if verbose: |
| | 20 | print snippet |
| | 21 | assert isinstance(snippet, str), type(snippet) |
| | 22 | assert snippet.count('\n') == 1, snippet.count('\n') |
| | 23 | data, pointer = snippet.split('\n') |
| | 24 | assert len(data) < 82, len(data) |
| | 25 | assert data[len(pointer)-1] == '*', data[len(pointer)-1] |
| 8 | | def _testMarks(self, test_name, marks_filename): |
| 9 | | inputs = file(marks_filename, 'rb').read().split('---\n')[1:] |
| 10 | | for input in inputs: |
| 11 | | index = 0 |
| 12 | | line = 0 |
| 13 | | column = 0 |
| 14 | | while input[index] != '*': |
| 15 | | if input[index] == '\n': |
| 16 | | line += 1 |
| 17 | | column = 0 |
| 18 | | else: |
| 19 | | column += 1 |
| 20 | | index += 1 |
| 21 | | mark = Mark(test_name, index, line, column, unicode(input), index) |
| 22 | | snippet = mark.get_snippet(indent=2, max_length=79) |
| 23 | | #print "INPUT:" |
| 24 | | #print input |
| 25 | | #print "SNIPPET:" |
| 26 | | #print snippet |
| 27 | | self.failUnless(isinstance(snippet, str)) |
| 28 | | self.failUnlessEqual(snippet.count('\n'), 1) |
| 29 | | data, pointer = snippet.split('\n') |
| 30 | | self.failUnless(len(data) < 82) |
| 31 | | self.failUnlessEqual(data[len(pointer)-1], '*') |
| | 29 | if __name__ == '__main__': |
| | 30 | import test_appliance |
| | 31 | test_appliance.run(globals()) |