def test_record_assignments(self): statements = rewrite.record_assignments(self.test_input) self.assertEqual(len(statements), 2) self.assertEqual(len([s for s in statements.values() if s.is_assignment]), 2) for label, statement in statements.items(): self.assertEqual(statement.label, self.answers[label]['label']) self.assertEqual(len(statement.alternatives), len(self.answers[label]['alternatives'])) self.assertEqual(statement.line, self.answers[label]['line']) for q,a in zip(statement.alternatives, self.answers[label]['alternatives']): self.assertEqual(str(q.content), str(a["content"])) self.assertEqual(q.start, a['start']) self.assertEqual(q.end, a['end']) self.assertEqual(str(statement.content[q.start:q.end]), str(q.content))
def test_dump_statements(self): statements = rewrite.record_assignments(self.test_input) statements = rewrite.record_blocks(self.test_input, statements) json_statements = json.loads(rewrite.dump_statements(self.test_input, statements)) self.assertEqual(json_statements['package'], "testing_inputs.maybe") self.assertEqual(len(json_statements['statements']), 8)