Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_approved_filename(self, basename=None):
basename = basename or self.get_basename()
return basename + Namer.APPROVED + self.extension_with_dot
def test_alternative_extension(self):
n = Namer(extension='.html')
filename = n.get_approved_filename('./stuff')
self.assertEqual(filename, './stuff.approved.html')
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)
def get_received_filename(self, basename=None):
basename = basename or self.get_basename()
return basename + Namer.RECEIVED + self.extension_with_dot
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])
def __init__(self, extension=None):
Namer.__init__(self, extension)
self.set_for_stack(inspect.stack(1))
self.config = None
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)