Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_site.PthFile Class Reference
Inheritance diagram for test.test_site.PthFile:
Inheritance graph
[legend]
Collaboration diagram for test.test_site.PthFile:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def create
def cleanup

Public Attributes

 filename
 base_dir
 file_path
 imported
 good_dirname
 bad_dirname
 good_dir_path
 bad_dir_path
 imported_module
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Detailed Description

Helper class for handling testing of .pth files

Definition at line 247 of file test_site.py.


Constructor & Destructor Documentation

def test.test_site.PthFile.__init__ (   self,
  filename_base = TESTFN,
  imported = "time",
  good_dirname = "__testdir__",
  bad_dirname = "__bad" 
)
Initialize instance variables

Definition at line 251 of file test_site.py.

00251 
00252                     good_dirname="__testdir__", bad_dirname="__bad"):
00253         """Initialize instance variables"""
00254         self.filename = filename_base + ".pth"
00255         self.base_dir = os.path.abspath('')
00256         self.file_path = os.path.join(self.base_dir, self.filename)
00257         self.imported = imported
00258         self.good_dirname = good_dirname
00259         self.bad_dirname = bad_dirname
00260         self.good_dir_path = os.path.join(self.base_dir, self.good_dirname)
00261         self.bad_dir_path = os.path.join(self.base_dir, self.bad_dirname)

Here is the caller graph for this function:


Member Function Documentation

def test.test_site.PthFile.cleanup (   self,
  prep = False 
)
Make sure that the .pth file is deleted, self.imported is not in
sys.modules, and that both self.good_dirname and self.bad_dirname are
not existing directories.

Definition at line 284 of file test_site.py.

00284 
00285     def cleanup(self, prep=False):
00286         """Make sure that the .pth file is deleted, self.imported is not in
00287         sys.modules, and that both self.good_dirname and self.bad_dirname are
00288         not existing directories."""
00289         if os.path.exists(self.file_path):
00290             os.remove(self.file_path)
00291         if prep:
00292             self.imported_module = sys.modules.get(self.imported)
00293             if self.imported_module:
00294                 del sys.modules[self.imported]
00295         else:
00296             if self.imported_module:
00297                 sys.modules[self.imported] = self.imported_module
00298         if os.path.exists(self.good_dir_path):
00299             os.rmdir(self.good_dir_path)
00300         if os.path.exists(self.bad_dir_path):
00301             os.rmdir(self.bad_dir_path)

Here is the caller graph for this function:

Create a .pth file with a comment, blank lines, an ``import
<self.imported>``, a line with self.good_dirname, and a line with
self.bad_dirname.

Creation of the directory for self.good_dir_path (based off of
self.good_dirname) is also performed.

Make sure to call self.cleanup() to undo anything done by this method.

Definition at line 262 of file test_site.py.

00262 
00263     def create(self):
00264         """Create a .pth file with a comment, blank lines, an ``import
00265         <self.imported>``, a line with self.good_dirname, and a line with
00266         self.bad_dirname.
00267 
00268         Creation of the directory for self.good_dir_path (based off of
00269         self.good_dirname) is also performed.
00270 
00271         Make sure to call self.cleanup() to undo anything done by this method.
00272 
00273         """
00274         FILE = open(self.file_path, 'w')
00275         try:
00276             print("#import @bad module name", file=FILE)
00277             print("\n", file=FILE)
00278             print("import %s" % self.imported, file=FILE)
00279             print(self.good_dirname, file=FILE)
00280             print(self.bad_dirname, file=FILE)
00281         finally:
00282             FILE.close()
00283         os.mkdir(self.good_dir_path)


Member Data Documentation

Definition at line 260 of file test_site.py.

Definition at line 258 of file test_site.py.

Definition at line 254 of file test_site.py.

Definition at line 255 of file test_site.py.

Definition at line 253 of file test_site.py.

Definition at line 259 of file test_site.py.

Definition at line 257 of file test_site.py.

Definition at line 256 of file test_site.py.

Definition at line 291 of file test_site.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.


The documentation for this class was generated from the following file: