Commits

Anonymous committed 2783686

Added code to add root directory to sys.path in case script is run from top of package. Added code to each test to add parent directory of test file sys.path for the same reason.

  • Participants
  • Parent commits e1ba7b4

Comments (0)

Files changed (10)

File psmodulecheck/filechecker.py

 """Check that all expected file names exist in module folder and that that they
 conform to the expected names."""
 import os
-#win7 from psmodulecheck.console import (print_error, print_pass)
-#win7 from psmodulecheck import metachecker, questions
 from console import (print_error, print_pass)
 import metachecker
 import questions

File psmodulecheck/metachecker.py

 from xml.dom import minidom
 import os
+from console import (print_pass, print_error)
 
-#win7 from psmodulecheck.console import (print_pass, print_error)
-from console import (print_pass, print_error)
 
 def check_meta_contents(meta_file_name, author_name):
     """

File psmodulecheck/psmodulecheck.py

 """
 import sys
 import os
+
+sys.path.append(os.path.dirname(os.path.realpath(__file__)))
 import console
 import filechecker
 import fullcoursecreator
 import metachecker
 import settings
 import questions
-
 import user
 import utilities
 
-
 def main(user_suffix='--'):
     starting_dir = os.getcwd()
     try:
 
         print(starting_dir)
         settings_dir = os.path.dirname(os.path.realpath(__file__))
-        config = settings.create_from_file(os.path.join(settings_dir,settings.SETTINGS_FILE))
+        config = settings.create_from_file(os.path.join(settings_dir, settings.SETTINGS_FILE))
         fc = filechecker.FileChecker(config)
 
         keep_looping = True

File psmodulecheck/questions.py

 """
 
 import os
-
-#win7 from psmodulecheck.console import (print_error, print_pass)
 from console import (print_error, print_pass)
 
 

File psmodulecheck/temp_project.py

-import os
-from psmodulecheck import (settings)
-
-
-class TempProject:
-    """Creates a configuration for a temporary PS project, and manages
-    the creation of files in that directory if requested.
-
-    """
-    def __init__(self, root):
-        """Create a new temporary project at ROOT.
-        """
-        self.path = root
-
-        config_dict = {
-            "path": self.path,
-            "shortId": "qt-intro",
-            "courseId": "introduction-qt-cplusplus-framework",
-            "author": "tod-gentille",
-            "createFullCourse": True,
-            "fullCourseDestinationPrefix": "E:\\DropBox\\tod-gentille-test",
-            "metaSuffix": ".meta",
-            "modulePrefix": "-m",
-            "maxQuestionLength": 150,
-            "maxAnswerLength": 100,
-            "demoFiles": [os.path.join(self.path, f)
-                          for f in ("no-demos.txt", "demos.zip")],
-            "questionFiles": [os.path.join(self.path, f)
-                              for f in ("no-questions.txt", "questions.txt")],
-            "slideFiles": [os.path.join(self.path, f)
-                              for f in ("slides.ppt", "slides.pptx", "slides.pdf")],
-            "validQuestionFileIndex": 1,
-            "questionStart": "Q)",
-            "answerStart": "*",
-            "discriminatorStart": "-",
-            "moduleLinkStart": "=",
-            "questionFileComment": "#"
-        }
-
-        self._config = settings.create_from_dict(config_dict)
-
-    @property
-    def config(self):
-        """The ``Settings`` associated with this project."""
-        return self._config
-
-    def create_files(self):
-        """Create the questions, demos, and meta files for the
-        project.
-        """
-        for f in (self.config.question_files[0],
-                  self.config.demo_files[0],
-                  os.path.join(self.path,self.config.get_meta_filename())):
-            with open(f, 'w+'):
-                pass
-
-

File psmodulecheck/tempproject.py

+import os
+# from psmodulecheck import (settings)
+import settings
+
+
+class TempProject:
+    """Creates a configuration for a temporary PS project, and manages
+    the creation of files in that directory if requested.
+
+    """
+
+    def __init__(self, root):
+        """Create a new temporary project at ROOT.
+        """
+        self.path = root
+
+        config_dict = {
+            "path": self.path,
+            "shortId": "qt-intro",
+            "courseId": "introduction-qt-cplusplus-framework",
+            "author": "tod-gentille",
+            "createFullCourse": True,
+            "fullCourseDestinationPrefix": "E:\\DropBox\\tod-gentille-test",
+            "metaSuffix": ".meta",
+            "modulePrefix": "-m",
+            "maxQuestionLength": 150,
+            "maxAnswerLength": 100,
+            "demoFiles": [os.path.join(self.path, f)
+                          for f in ("no-demos.txt", "demos.zip")],
+            "questionFiles": [os.path.join(self.path, f)
+                              for f in ("no-questions.txt", "questions.txt")],
+            "slideFiles": [os.path.join(self.path, f)
+                           for f in ("slides.ppt", "slides.pptx", "slides.pdf")],
+            "validQuestionFileIndex": 1,
+            "questionStart": "Q)",
+            "answerStart": "*",
+            "discriminatorStart": "-",
+            "moduleLinkStart": "=",
+            "questionFileComment": "#"
+        }
+
+        self._config = settings.create_from_dict(config_dict)
+
+    @property
+    def config(self):
+        """The ``Settings`` associated with this project."""
+        return self._config
+
+    def create_files(self):
+        """Create the questions, demos, and meta files for the
+        project.
+        """
+        for f in (self.config.question_files[0],
+                  self.config.demo_files[0],
+                  os.path.join(self.path, self.config.get_meta_filename())):
+            with open(f, 'w+'):
+                pass
+
+

File psmodulecheck/tests/test_filechecker.py

 import sys
 import tempfile
 import unittest
-import temp_project
 
+package_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
+sys.path.append(package_path)
+
+import tempproject
 from psmodulecheck import (console,
-                           filechecker )
+                           filechecker,
+                           )
 
 
 class FilecheckerTests(unittest.TestCase):
             console.init()       # doing init from there causes colors
                                  # to NOT work
         cls.tempdir = tempfile.TemporaryDirectory()
-        proj = temp_project.TempProject(cls.tempdir.name)
+        proj = tempproject.TempProject(cls.tempdir.name)
         proj.config.user_set_full_path("01")
         proj.create_files()
         cls.fc = filechecker.FileChecker(proj.config)
             console.init()       # doing init from there causes colors
                                  # to NOT work
         cls.tempdir = tempfile.TemporaryDirectory()
-        proj = temp_project.TempProject(cls.tempdir.name)
+        proj = tempproject.TempProject(cls.tempdir.name)
         proj.config.user_set_full_path("01")
         cls.fc = filechecker.FileChecker(proj.config)
         console.print_warning("Error messages will appear if these tests pass")

File psmodulecheck/tests/test_metachecker.py

 import sys
 import tempfile
 
+package_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
+sys.path.append(package_path)
 import metachecker
 import console
-import temp_project
+import tempproject
 
 
 class MetacheckerTests(unittest.TestCase):
 
         cls.author = 'tod-gentille'
         cls.tempdir = tempfile.TemporaryDirectory()
-        proj = temp_project.TempProject(cls.tempdir.name)
+        proj = tempproject.TempProject(cls.tempdir.name)
         proj.config.user_set_full_path("01")
         proj.config.author = cls.author
         cls.meta_filepath = os.path.join(proj.path, proj.config.get_meta_filename())

File psmodulecheck/tests/test_questions.py

 import sys
 import tempfile
 
+package_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
+sys.path.append(package_path)
 import console
 import questions
-import temp_project
+import tempproject
 
 
 class QuestionTests(unittest.TestCase):
         cls.cur_dir = os.getcwd()
         cls.tempdir = tempfile.TemporaryDirectory()
 
-        proj = temp_project.TempProject(cls.tempdir.name)
+        proj = tempproject.TempProject(cls.tempdir.name)
         proj.config.user_set_full_path("01")
         cls.meta_filename = proj.config.get_meta_filename()
         cls.q = questions.Question(proj.config)
         console.print_warning("Error messages are to be expected here."
                               "Testing bad question data.")
         cls.tempdir = tempfile.TemporaryDirectory()
-        proj = temp_project.TempProject(cls.tempdir.name)
+        proj = tempproject.TempProject(cls.tempdir.name)
         proj.config.user_set_full_path("01")
         cls.meta_filename = proj.config.get_meta_filename()
         cls.q = questions.Question(proj.config)

File psmodulecheck/utilities.py

 """A collection of useful utilities"""
 import console
 
+
 def get_user_response_yn(prompt):
     """Prompt the user with the passed message and add (Y/N) to end
     Keeps prompting until yYNn is entered
             return True
         if answer[0].upper() == 'N':
             return False
-        console.print_error('Please enter a Y or N')
+        console.print_error('Please enter a Y or N')
+
+
+        # import adjustpath
+        # sys.path.append(os.path.dirname(os.path.realpath(__file__)))
+        # for path in sys.path:
+        #     print (path)