def ask_directory(prompt, default=None, starting=None): if default is not None: prompt = prompt + ('[%s] ' % default) if lisp.fboundp(lisp['read-directory-name']): result = lisp.read_directory_name(prompt, starting, default) else: result = lisp.read_file_name(prompt, starting, default) if result == '' and default is not None: return default return result
def ask_directory(self, prompt, default=None, starting=None): location = starting or default if location is not None: prompt = prompt + ('[%s] ' % location) if lisp.fboundp(lisp['read-directory-name']): # returns default when starting is entered result = lisp.read_directory_name(prompt, location, location) else: result = lisp.read_file_name(prompt, location, location) if result == '' and location is not None: return location return result
# Retrieve current buffer file name filename = lisp.buffer_file_name() filename = os.path.abspath(filename) # Find the test path test_path = utils.find_tests_path(filename) # Find the module_name module_name = utils.find_module_name(filename) # If not found, ask the user for a directory if test_path == None: test_path = os.path.join(os.path.dirname(filename), "tests") test_path = lisp.read_file_name("Where should I create the 'tests' directory ?", test_path) # Find the point where tests and current file names diverge BASE = os.path.abspath(os.path.join(test_path, "..")) # Try to infer the small name for the module and so the test file name if filename.startswith(BASE): parts = filename[len(BASE) + 1:-3].split("/") testfilename = os.path.join(test_path, "_".join(parts), "test_" + "_".join(parts) + ".py") else: testfilename = lisp.read_file_name("Where should I create this test ?", os.path.join(test_path, "test.py") ) # Create the test directory try: os.makedirs(os.path.dirname(testfilename)) except OSError, e:
if filename == None: raise Exception( "Please open the file where you want to create the test or select a file for which you want to create a test." ) filename = os.path.abspath(filename) # Find the test path test_path = utils.find_tests_path(filename) # Find the module_name module_name = utils.find_module_name(filename) # If not found, ask the user for a directory if test_path == None: test_path = os.path.join(os.path.dirname(filename), "tests") test_path = lisp.read_file_name( "Where should I create the 'tests' directory ?", test_path) # Find the point where tests and current file names diverge BASE = os.path.abspath(os.path.join(test_path, "..")) if "test" not in filename: # Try to infer the small name for the module and so the test file name if filename.startswith(BASE): parts = filename[len(BASE) + 1:-3].split("/") testfilename = os.path.join(test_path, "_".join(parts), "test_" + "_".join(parts) + ".py") else: testfilename = lisp.read_file_name("Where should I create this test ?", os.path.join(test_path, "test.py")) else: testfilename = filename