Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
newline: An optional string that controls how universal newlines work when comparing data.
It can be None, '', '\n', '\r', and '\r\n'. If None (the default) universal newlines are
enabled and any '\n' characters are translated to the system default line separator
given by os.linesep. If newline is '', no translation takes place. If newline is any of
the other legal values, any '\n' characters written are translated to the given string.
Raises:
ApprovalException: If the verification fails because the given string does not match the
approved string.
ValueError: If data cannot be encoded using the specified encoding when errors is set to
None or 'strict'.
"""
reporter = get_reporter(reporter)
approver = FileApprover()
writer = StringWriter(data, encoding=encoding, errors=errors, newline=newline)
error = approver.verify(namer, writer, reporter)
if error is not None:
raise ApprovalException(error)
def test_returns_none_when_files_are_same_files(self):
namer = get_default_namer()
writer = StringWriter("b")
reporter = GenericDiffReporterFactory().get_first_working()
approver = FileApprover()
error = approver.verify(namer, writer, reporter)
self.assertEqual(None, error)
def test_compare_different_files(self):
approver = FileApprover()
reporter = ReporterForTesting()
approver.verify_files("a.txt", "b.txt", reporter)
self.assertTrue(reporter.called)
def test_full(self):
namer = get_default_namer()
writer = StringWriter("b")
reporter = ReporterForTesting()
approver = FileApprover()
approver.verify(namer, writer, reporter)
self.assertTrue(reporter.called)
def test_returns_error_when_files_are_different(self):
namer = get_default_namer()
writer = StringWriter("b")
reporter = ReporterForTesting()
approver = FileApprover()
error = approver.verify(namer, writer, reporter)
self.assertEqual("Approval Mismatch", error)
@staticmethod
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)