def setUp(self): self.data = AchievementData({ 'time.start': datetime.now(), 'time.finish': datetime.now() }) self.stream = StringIO() self.data.save(self.stream) self.stream.seek(0)
def finalize(self, data, result): if self.enabled and data['result.success']: coverage = self.coverage() coverage.load() report = StringIO() coverage.report(file=report) report_string = report.getvalue() last_line = report_string.splitlines()[-1] match = re.match( r'TOTAL\s+(?P<stmts>\d+)\s+(?P<exec>\d+)\s+' r'(?P<cover>\d+)%', last_line) if match: statements = int(match.group('stmts')) executed = int(match.group('exec')) percent_covered = int(match.group('cover')) if percent_covered == 100: level = int(math.log(statements, 2) - 7) data.unlock(self)
def test_data_is_serializable(self): if self.plugin.enabled: stream = StringIO() self.plugin.data.save(stream) self.assertTrue(stream.getvalue())
def setUp(self): self.stream = StringIO()
def test_save_writes_data_to_stream(self): stream = StringIO() dump(self.data, stream, AchievementData.PICKLE_PROTOCOL) self.assertEqual(self.stream.getvalue(), stream.getvalue())