Example #1
0
    def test_verify_custom_comparator_allows_all_inputs(self):
        class EverythingIsTrue(Comparator):
            def compare(self, received_path: str, approved_path: str) -> bool:
                return True

        verify(random.random(),
               options=Options().with_comparator(EverythingIsTrue()))
Example #2
0
 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_simple(self):
     verify(
         "Hello",
         options=Options().with_reporter(
             GenericDiffReporter.create(
                 r"C:\my\favorite\diff\utility.exe")),
     )
Example #4
0
 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, Options().comparator)
     self.assertEqual(None, error)
Example #5
0
 def test_verify_automatic_approval(self):
     delete_approved_file()
     with pytest.raises(ApprovalException):
         verify(2,
                options=Options().with_reporter(
                    reporter=ReporterThatAutomaticallyApproves()))
     verify(2)
Example #6
0
 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_document_existing_reporters(self) -> None:
        reporters = self.factory.list()
        reporters.sort()
        markdown = ""
        for reporter in reporters:
            markdown += f"* { reporter}\n"

        verify(markdown,options=Options().for_file.with_extension(".md"))
Example #8
0
    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, Options().comparator)
        import re

        replaced = re.sub("ved: .*approved_files.", "ved: <rootdir>/", error)

        verify(replaced)
Example #9
0
 def test_with_specific_reporter(self):
     sample = "Welcome To Approvals"
     verify(sample, options=Options().with_reporter(PythonNativeReporter()))
 def test(self) -> None:
     details = ReleaseDetails(Version(1, 2, 3), Version(1, 2, 4), True,
                              ProjectDetails())
     scrubber = Options().with_scrubber(
         lambda t: t.replace('"../../conan-', '"../../../conan/conan-'))
     verify_as_json(details, options=scrubber)
def test_simulator_produces_correct_output():
    np_array = np.full(shape=(32, 16), fill_value=42, dtype=np.int64)
    verify_binary(serialize_ndarray(np_array),
                  ".npy",
                  options=Options().with_reporter(NDArrayDiffReporter()))
 def test_simple(self):
     verify("Hello",
            options=Options().with_reporter(report_with_beyond_compare()))
Example #13
0
 def test_newlines_at_end_of_files(self) -> None:
     verify(
         "There should be a blank line underneath this",
         options=Options().with_reporter(ReportWithPycharm()),
     )
Example #14
0
 def test_scrubbed_files(self):
     verify_file("a.txt",
                 options=Options().with_scrubber(lambda t: "<scrubbed>"))
Example #15
0
 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 test_simple(self):
     verify("Hello",
            options=Options().with_reporter(
                self.factory.get("BeyondCompare")))
Example #17
0
 def test_exist_file_with_modified_extension(self):
     verify_file(get_adjacent_file("sample.xml"),
                 options=Options().for_file.with_extension(".json"))