def test_get_home_dir_2(): """Testcase for py2exe logic, compressed lib """ sys.frozen = True #fake filename for IPython.__init__ IPython.__file__ = abspath(join(HOME_TEST_DIR, "Library.zip/IPython/__init__.py")).lower() home_dir = genutils.get_home_dir() nt.assert_equal(home_dir, abspath(HOME_TEST_DIR).lower())
def test_get_home_dir_5(): """Testcase $HOME is not set, os=='nt' env['HOMEDRIVE'],env['HOMEPATH'] points to path.""" os.name = 'nt' if 'HOME' in env: del env['HOME'] env['HOMEDRIVE'], env['HOMEPATH'] = os.path.splitdrive(HOME_TEST_DIR) home_dir = genutils.get_home_dir() nt.assert_equal(home_dir, abspath(HOME_TEST_DIR))
def test_get_home_dir_2(): """Testcase for py2exe logic, compressed lib """ sys.frozen = True #fake filename for IPython.__init__ IPython.__file__ = abspath( join(HOME_TEST_DIR, "Library.zip/IPython/__init__.py")).lower() home_dir = genutils.get_home_dir() nt.assert_equal(home_dir, abspath(HOME_TEST_DIR).lower())
def test_get_home_dir_6(): """Testcase $HOME is not set, os=='nt' env['HOMEDRIVE'],env['HOMEPATH'] do not point to path. env['USERPROFILE'] points to path """ os.name = 'nt' if 'HOME' in env: del env['HOME'] env['HOMEDRIVE'], env['HOMEPATH'] = os.path.abspath(TEST_FILE_PATH), "DOES NOT EXIST" env["USERPROFILE"] = abspath(HOME_TEST_DIR) home_dir = genutils.get_home_dir() nt.assert_equal(home_dir, abspath(HOME_TEST_DIR))
def test_get_home_dir_6(): """Testcase $HOME is not set, os=='nt' env['HOMEDRIVE'],env['HOMEPATH'] do not point to path. env['USERPROFILE'] points to path """ os.name = 'nt' if 'HOME' in env: del env['HOME'] env['HOMEDRIVE'], env['HOMEPATH'] = os.path.abspath( TEST_FILE_PATH), "DOES NOT EXIST" env["USERPROFILE"] = abspath(HOME_TEST_DIR) home_dir = genutils.get_home_dir() nt.assert_equal(home_dir, abspath(HOME_TEST_DIR))
def connectDB(fname='ipnotebook.db', ipythondir=None): """ BROKEN TO BE MOVED TO CONFIG SYSTEM Connect to aa notebook database, or attempt to create a new one if none is found. """ f = resolveFilePath(fname, ipythondir) print f if f is None: print "Could not find DB, attempting to create new DB" err = DBError("Could not create DB") if ipythondir is not None: ipdir = ipythondir elif os.environ.get("IPYTHONDIR") is not None: ipdir = os.environ.get("IPYTHONDIR") else: try: home = get_home_dir() ipdir = home + '/.ipython' if not os.path.exists(ipdir): ipdir = home except: raise err q = 'sqlite:///%s' % (ipdir + '/' + fname) # print q engine = sqla.create_engine(q) try: engine.connect() except sqla.exceptions.DBAPIError: raise err metadata.connect(engine) metadata.create_all() return metadata else: engine = sqla.create_engine('sqlite:///%s' % (f)) metadata.connect(engine) # checkDB(DB) return metadata
def test_get_home_dir_7(): """Testcase $HOME is not set, os=='nt' env['HOMEDRIVE'],env['HOMEPATH'], env['USERPROFILE'] missing """ os.name = 'nt' if 'HOME' in env: del env['HOME'] if 'HOMEDRIVE' in env: del env['HOMEDRIVE'] #Stub windows registry functions def OpenKey(x, y): class key: def Close(self): pass return key() def QueryValueEx(x, y): return [abspath(HOME_TEST_DIR)] wreg.OpenKey = OpenKey wreg.QueryValueEx = QueryValueEx home_dir = genutils.get_home_dir() nt.assert_equal(home_dir, abspath(HOME_TEST_DIR))
def resolveFilePath(filename, ipythondir=None): """Resolve filenames into absolute paths. This function looks in the following directories in order: 1. In the current working directory or by absolute path with ~ expanded 2. In ipythondir if that is set 3. In the IPYTHONDIR environment variable if it exists 4. In the ~/.ipython directory Note: The IPYTHONDIR is also used by the trunk version of IPython so changing it will also affect it was well. """ # In cwd or by absolute path with ~ expanded trythis = os.path.expanduser(filename) if os.path.isfile(trythis): return trythis # In ipythondir if it is set if ipythondir is not None: trythis = ipythondir + '/' + filename if os.path.isfile(trythis): return trythis # In the IPYTHONDIR environment variable if it exists IPYTHONDIR = os.environ.get('IPYTHONDIR') if IPYTHONDIR is not None: trythis = IPYTHONDIR + '/' + filename if os.path.isfile(trythis): return trythis # In the ~/.ipython directory trythis = get_home_dir() + '/.ipython/' + filename if os.path.isfile(trythis): return trythis return None
def __init__(self, kernelCount=-1, filename=""): self.kernels = [] self.count = 0 self.kernelCount = kernelCount self.filename = get_home_dir() + "/.ipython/" + filename
def test_get_home_dir_3(): """Testcase $HOME is set, then use its value as home directory.""" env["HOME"] = HOME_TEST_DIR home_dir = genutils.get_home_dir() nt.assert_equal(home_dir, env["HOME"])
def test_get_home_dir(): """Make sure we can get the home directory.""" home_dir = genutils.get_home_dir()