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 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)
class TestAchievementData(unittest.TestCase): 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 test_is_dict(self): self.assert_(isinstance(self.data, dict)) def test_save_writes_data_to_stream(self): stream = StringIO() dump(self.data, stream, AchievementData.PICKLE_PROTOCOL) self.assertEqual(self.stream.getvalue(), stream.getvalue()) def test_load_reads_data_from_stream(self): data = AchievementData.load(self.stream) self.assertEqual(self.data, data)
class TestAchievementData(unittest.TestCase): 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 test_is_dict(self): self.assert_(isinstance(self.data, dict)) def test_save_writes_data_to_stream(self): stream = StringIO() dump(self.data, stream, AchievementData.PICKLE_PROTOCOL) self.assertEqual(self.stream.getvalue(), stream.getvalue()) def test_load_reads_data_from_stream(self): data = AchievementData.load(self.stream) self.assertEqual(self.data, data)
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())
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)