def test_last_span_missing(self): missing_tokens = [] def preprocessor(tokens): missing_tokens.append(tokens[-1]) return tokens[:-1] self.file = data.Submission(".", ["foo.py"], preprocessor=preprocessor).files[0] spans = api.missing_spans(self.file) resulting_span = self.span(missing_tokens[0].start, len(self.content)) self.assertEqual(spans, [resulting_span])
def test_first_span_missing(self): missing_tokens = [] def preprocessor(tokens): missing_tokens.append(tokens[0]) return tokens[1:] self.file = data.Submission(".", ["foo.py"], preprocessor=preprocessor).files[0] spans = api.missing_spans(self.file) resulting_span = self.span(0, missing_tokens[0].end) self.assertEqual(spans, [resulting_span])
def test_middle_span_missing(self): missing_tokens = [] def preprocessor(tokens): middle = len(tokens) // 2 missing_tokens.append(tokens[middle]) return tokens[:middle] + tokens[middle + 1:] self.file = data.Submission(".", ["foo.py"], preprocessor=preprocessor).files[0] spans = api.missing_spans(self.file) resulting_span = self.span(missing_tokens[0].start, missing_tokens[0].end) self.assertEqual(spans, [resulting_span])
def test_all_spans_missing(self): self.file = data.Submission(".", ["foo.py"], preprocessor=lambda tokens: []).files[0] resulting_span = self.span(0, len(self.content)) spans = api.missing_spans(self.file) self.assertEqual(spans, [resulting_span])