How to use the approvaltests.core.namer.Namer function in approvaltests

To help you get started, we’ve selected a few approvaltests examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github approvals / ApprovalTests.Python / approvaltests / core / namer.py View on Github external
def get_approved_filename(self, basename=None):
        basename = basename or self.get_basename()
        return basename + Namer.APPROVED + self.extension_with_dot
github approvals / ApprovalTests.Python / tests / test_namer.py View on Github external
def test_alternative_extension(self):
        n = Namer(extension='.html')
        filename = n.get_approved_filename('./stuff')
        self.assertEqual(filename, './stuff.approved.html')
github approvals / ApprovalTests.Python / tests / reporters / test_genericdiffreporter.py View on Github external
def test_approved_file_not_changed_when_one_exists_already(self):
        namer = Namer()
        approved_contents = "Approved"
        approved = namer.get_approved_filename()
        os.remove(approved)
        with open(approved, 'w') as approved_file:
            approved_file.write(approved_contents)
        reporter = self.factory.get("BeyondCompare4")
        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)
github approvals / ApprovalTests.Python / approvaltests / core / namer.py View on Github external
def get_received_filename(self, basename=None):
        basename = basename or self.get_basename()
        return basename + Namer.RECEIVED + self.extension_with_dot
github approvals / ApprovalTests.Python / approvaltests / core / namer.py View on Github external
subdirectory = self.get_config().get('subdirectory', '')
        return os.path.join(self.get_directory(), subdirectory, file_name)

    def get_received_filename(self, basename=None):
        basename = basename or self.get_basename()
        return basename + Namer.RECEIVED + self.extension_with_dot

    def get_approved_filename(self, basename=None):
        basename = basename or self.get_basename()
        return basename + Namer.APPROVED + self.extension_with_dot

    def set_extension(self, extension):
        self.extension_with_dot = extension


class StackFrameNamer(Namer):
    Directory = ''
    MethodName = ''
    ClassName = ''

    def __init__(self, extension=None):
        Namer.__init__(self, extension)
        self.set_for_stack(inspect.stack(1))
        self.config = None

    def set_for_stack(self, caller):
        frame = self.get_test_frame(caller)
        stacktrace = caller[frame]
        self.MethodName = stacktrace[3]
        self.ClassName = self.get_class_name_for_frame(stacktrace)
        self.Directory = os.path.dirname(stacktrace[1])
github approvals / ApprovalTests.Python / approvaltests / core / namer.py View on Github external
def __init__(self, extension=None):
        Namer.__init__(self, extension)
        self.set_for_stack(inspect.stack(1))
        self.config = None
github approvals / ApprovalTests.Python / tests / reporters / test_genericdiffreporter.py View on Github external
def test_empty_approved_file_created_when_one_does_not_exist(self):
        namer = 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.report(received, approved)
        self.assertEqual(0, os.stat(approved).st_size)