Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 19 additions & 30 deletions ftplugin/python_pyunit.vim
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,19 @@ class BaseTestLayout(object):
parts[-1] = parts[-1][:-len(".py")]
return parts

def _join_path_with_root(self, source_file, source_root, path_type):
rel_source_file = self.relatize(source_file)
rel_source_root = self.relatize(source_root)
if not rel_source_file.startswith(rel_source_root):
raise RuntimeError("File %s is not under % root." % (source_file, path_type))
return _relpath(rel_source_file, rel_source_root)

def join_source_path_with_root(self, source_file):
return self._join_path_with_root(source_file, self.source_root, 'source')

def join_test_path_with_root(self, test_file):
return self._join_path_with_root(test_file, self.source_root, 'test')

def glue_parts(self, parts, use_under_under_init=False):
if use_under_under_init:
parts = parts + ['__init__.py']
Expand Down Expand Up @@ -278,22 +291,14 @@ class FlatLayout(BaseTestLayout):
return parts[0].startswith(self.prefix)

def get_test_file(self, source_file):
source_file = self.relatize(source_file)
if not source_file.startswith(self.source_root):
raise RuntimeError("File %s is not under the source root." % source_file)

source_file = _relpath(source_file, self.source_root)
source_file = self.join_source_path_with_root(source_file)
parts = self.break_down(source_file)
flat_file_name = "_".join(parts)
parts = [self.test_root] + [self.prefix + flat_file_name]
return self.glue_parts(parts)

def get_source_candidates(self, test_file):
test_file = self.relatize(test_file)
if not test_file.startswith(self.test_root):
raise RuntimeError("File %s is not under the test root." % test_file)

test_file = _relpath(test_file, self.test_root)
test_file = self.join_test_path_with_root(test_file)
parts = self.break_down(test_file)
if len(parts) != 1:
raise RuntimeError("Flat tests layout does not allow tests to be more than one directory deep.")
Expand All @@ -318,22 +323,14 @@ class FollowHierarchyLayout(BaseTestLayout):
return True

def get_test_file(self, source_file):
source_file = self.relatize(source_file)
if not source_file.startswith(self.source_root):
raise RuntimeError("File %s is not under the source root." % source_file)

source_file = _relpath(source_file, self.source_root)
source_file = self.join_source_path_with_root(source_file)
parts = self.break_down(source_file)
parts = map(lambda p: self.prefix + p, parts)
parts = [self.test_root] + parts
return self.glue_parts(parts)

def get_source_candidates(self, test_file):
test_file = self.relatize(test_file)
if not test_file.startswith(self.test_root):
raise RuntimeError("File %s is not under the test root." % test_file)

test_file = _relpath(test_file, self.test_root)
test_file = self.join_test_path_with_root(test_file)
parts = self.break_down(test_file)
parts = [strip_prefix(p, self.prefix) for p in parts]
if self.source_root:
Expand All @@ -354,22 +351,14 @@ class NoseLayout(BaseTestLayout):
return parts[-1].startswith(self.prefix)

def get_test_file(self, source_file):
source_file = self.relatize(source_file)
if not source_file.startswith(self.source_root):
raise RuntimeError("File %s is not under the source root." % source_file)

source_file = _relpath(source_file, self.source_root)
source_file = self.join_source_path_with_root(source_file)
parts = self.break_down(source_file)
parts[-1] = self.prefix + parts[-1]
parts = [self.test_root] + parts
return self.glue_parts(parts)

def get_source_candidates(self, test_file):
test_file = self.relatize(test_file)
if not test_file.startswith(self.test_root):
raise RuntimeError("File %s is not under the test root." % test_file)

test_file = _relpath(test_file, self.test_root)
test_file = self.join_test_path_with_root(test_file)
parts = self.break_down(test_file)
parts = [strip_prefix(p, self.prefix) for p in parts]
if self.source_root:
Expand Down