def test_constructs_valid_diff_command(self) -> None:
     reporter = cast(GenericDiffReporter, self.factory.get("BeyondCompare4"))
     namer = get_default_namer()
     received = namer.get_received_filename()
     approved = namer.get_approved_filename()
     command = reporter.get_command(received, approved)
     expected_command = [reporter.path, received, approved]
     self.assertEqual(command, expected_command)
Ejemplo n.º 2
0
def assert_equal_with_reporter(expected, actual, reporter=None):
    if actual == expected:
        return

    name = get_default_namer().get_file_name()
    expected_file = write_to_temporary_file(expected, name + ".expected.")
    actual_file = write_to_temporary_file(actual, name + ".actual.")
    get_reporter(reporter).report(actual_file, expected_file)
    raise AssertionError(
        'expected != actual\n  actual: "{}"\nexpected: "{}"'.format(
            actual, expected))
Ejemplo n.º 3
0
    def test_empty_approved_file_created_when_one_does_not_exist(self):
        namer = get_default_namer()
        received = namer.get_received_filename()
        approved = namer.get_approved_filename()
        if os.path.isfile(approved):
            os.remove(approved)
        self.assertFalse(os.path.isfile(approved))

        reporter = self.factory.get("BeyondCompare4")
        reporter.run_command = lambda command_array: None
        reporter.is_working = lambda: True
        reporter.report(received, approved)
        self.assertEqual(0, os.stat(approved).st_size)
    def test_approved_file_not_changed_when_one_exists_already(self) -> None:
        namer = get_default_namer()
        approved = namer.get_approved_filename()
        os.remove(approved)
        approved_contents = "Approved"
        with open(approved, "w") as approved_file:
            approved_file.write(approved_contents)
        reporter = self.factory.get("BeyondCompare4")
        setattr(reporter, "run_command", lambda command_array: None)

        reporter.report(namer.get_received_filename(), approved)

        with open(approved, "r") as approved_file:
            actual_contents = approved_file.read()
        self.assertEqual(actual_contents, approved_contents)
 def test_serialization(self) -> None:
     n = get_default_namer()
     saved_reporters_file = os.path.join(n.get_directory(), "saved-reporters.json")
     self.factory.save(saved_reporters_file)
     try:
         with open(saved_reporters_file, "r") as f:
             file_contents = f.read()
             # remove the absolute path to the python_native_reporter.py file since it is different on every machine
             regex = re.compile(r'.*"([^"]*)python_native_reporter.py')
             match = regex.findall(file_contents)
             if match:
                 file_contents = file_contents.replace(match[0], "")
             file_contents = file_contents.replace("python.exe", "python")
             verify(file_contents)
     finally:
         os.remove(saved_reporters_file)
 def test_deserialization(self) -> None:
     namer = get_default_namer()
     full_name = os.path.join(namer.get_directory(), "custom-reporters.json")
     reporters = self.factory.load(full_name)
     verify(to_json(reporters))
Ejemplo n.º 7
0
def test_received_filename():
    namer = get_default_namer()
    assert namer.get_received_filename().endswith("ApprovalTests.Python/tests/pytest/test_namer.test_received_filename.received.txt")
Ejemplo n.º 8
0
def test_received_filename():
    namer = get_default_namer()
    assert namer.get_received_filename().endswith(
        "ApprovalTests.Python/tests/pytest/test_namer.test_received_filename.received.txt"
    )