def test_writes_file(self): contents = "foo" + str(randint(0, 100)) sw = StringWriter(contents) filename = './stuff.txt' sw.write_received_file(filename) with open(filename, 'r') as received: self.assertEqual(contents, received.read()) os.remove(filename)
def test_returns_none_when_files_are_same_files(self): namer = Namer() writer = StringWriter("b") reporter = GenericDiffReporterFactory().get_first_working() approver = FileApprover() error = approver.verify(namer, writer, reporter) self.assertEqual(None, error)
def test_returns_error_when_files_are_different(self): namer = Namer() writer = StringWriter("b") reporter = TestingReporter() approver = FileApprover() error = approver.verify(namer, writer, reporter) self.assertEqual("Approval Mismatch", error)
def test_full(self): namer = Namer() writer = StringWriter("b") reporter = TestingReporter() approver = FileApprover() approver.verify(namer, writer, reporter) self.assertTrue(reporter.called)
def verify(data, reporter=None): if reporter is None: reporter = get_default_reporter() approver = FileApprover() namer = get_default_namer() writer = StringWriter(data) error = approver.verify(namer, writer, reporter) if error is not None: raise ApprovalException(error)
def test_compare_same_files(): approver = FileApprover() writer = StringWriter("a") writer.write_received_file("a.txt") shutil.copy("a.txt", "a_same.txt") approver.verify_files("a.txt", "a_same.txt", None)