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_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 verify_with_namer(data, namer, reporter): reporter = get_reporter(reporter) approver = FileApprover() writer = StringWriter(data) error = approver.verify(namer, writer, reporter) if error is not None: raise ApprovalException(error)
def test_full(self): namer = Namer() writer = StringWriter("b") reporter = TestingReporter() approver = FileApprover() approver.verify(namer, writer, 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, Options().comparator) self.assertTrue(reporter.called)
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, Options().comparator)
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) import re replaced = re.sub("ved: .*approved_files.", 'ved: <rootdir>/', error) verify(replaced)
def verify_with_namer_and_writer( namer: Namer, writer: Writer, reporter: Optional[Reporter], ) -> None: approver = FileApprover() reporter = get_reporter(reporter) error = approver.verify(namer, writer, reporter) if error: raise ApprovalException(error)
def verify_with_namer_and_writer( namer: Namer, writer: Writer, reporter: Optional[Reporter] = None, *, # enforce keyword arguments - https://www.python.org/dev/peps/pep-3102/ options: Optional[Options] = None ) -> None: options = initialize_options(options, reporter) approver = FileApprover() error = approver.verify(namer, writer, options.reporter, options.comparator) if error: raise ApprovalException(error)
def verify_with_namer(data, namer, reporter, encoding=None, errors=None, newline=None): """Verify string data against a previously approved version of the string. Args: data: A string containing the data to be compared with approved data from a previous run. On Python 2 this can be a bytes, str, or unicode object. On Python 3 this should be a str object. namer: A Namer instance used for naming approved and received data files. reporter: An optional Reporter. If None (the default), the default reporter will be used; see get_default_reporter(). encoding: An optional encoding to be used when serialising the data to a byte stream for comparison. If None (the default) a locale-dependent encoding will be used; see locale.getpreferredencoding(). errors: An optional string that specifies how encoding and decoding errors are to be handled If None (the default) or 'strict', raise a ValueError exception if there is an encoding error. Pass 'ignore' to ignore encoding errors. Pass 'replace' to use a replacement marker (such as '?') when there is malformed data. 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_compare_different_files(self): approver = FileApprover() reporter = TestingReporter() approver.verify_files("a.txt", "b.txt", reporter) self.assertTrue(reporter.called)
def test_compare_different_files(self): approver = FileApprover() reporter = ReporterForTesting() approver.verify_files("a.txt", "b.txt", reporter, Options().comparator) self.assertTrue(reporter.called)
def verify_with_namer_and_writer(namer, writer, reporter): approver = FileApprover() reporter = get_reporter(reporter) error = approver.verify(namer, writer, reporter) if error: raise ApprovalException(error)