Thanks to visit codestin.com
Credit goes to github.com

Skip to content

does not discover project root #29

@willjp

Description

@willjp

Hey! Thank you very much for this plugin, it is fantastic!

I'm just writing because I noticed that while using 'follow-hierarchy' the root directory is being properly discovered by 'find_project_root', but not used in FollowHierarchyLayout's method 'get_test_file'. This isn't the cleanest solution (gets rid of the relative path for the 'confirm') but it detects the test_file.

diff --git a/ftplugin/python_pyunit.vim b/ftplugin/python_pyunit.vim
index 4975a09..8c80fb6 100644
--- a/ftplugin/python_pyunit.vim
+++ b/ftplugin/python_pyunit.vim
@@ -318,15 +318,22 @@ class FollowHierarchyLayout(BaseTestLayout):
         return True

     def get_test_file(self, source_file):
+        """ get absolute path to test 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)
+        project_root = find_project_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)
+
+        testfile_path = self.glue_parts(parts)
+        testfile_path = project_root +'/'+ testfile_path
+
+        return testfile_path

     def get_source_candidates(self, test_file):
         test_file = self.relatize(test_file)
@@ -445,10 +452,13 @@ def lcd_to_project_root(path):
 def switch_to_test_file_for_source_file(path):
     testfile = get_test_file_for_source_file(path)
     testdir = os.path.dirname(testfile)
+
     if not os.path.isfile(testfile):
         if int(vim.eval('g:PyUnitConfirmTestCreation')):
             # Ask the user for confirmation
-            rel_testfile = _relpath(testfile, find_project_root(path))
+            #rel_testfile = _relpath(testfile, find_project_root(path))
+            rel_testfile = testfile
+
             msg = 'confirm("Test file does not exist yet. Create %s now?", "&Yes\n&No")' % rel_testfile
             if int(vim.eval(msg)) != 1:
                 return

Have a great weekend!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions