Source code for tests.30_libs.040_PySourceInfo.getModuleFilePathName.CallCase
from __future__ import absolute_import
import unittest
import os
import pysourceinfo.PySourceInfo
#
#######################
#
[docs]class CallUnits(unittest.TestCase):
[docs] def testCase000(self):
import sys
_s=sys.path[:]
sys.path.insert(0,os.path.dirname(__file__)+os.sep+'..')
import PySourceInfo_check_tests #@UnresolvedImport
fpn = pysourceinfo.PySourceInfo.getModuleFilePathName(pysourceinfo.PySourceInfo)
fm = PySourceInfo_check_tests.check_callback(pysourceinfo.PySourceInfo.getCallerModule,0)
fx = pysourceinfo.PySourceInfo.getModuleFilePathName(fm)
assert os.path.normpath(fx) == fpn
if len(fx) >4:
assert fx[-4:] == '.pyc' # just ignore first call
[ sys.path.pop() for x in range(len(sys.path)) ] #@UnusedVariable
sys.path.extend(_s)
[docs] def testCase001(self):
import sys
_s=sys.path[:]
sys.path.insert(0,os.path.dirname(__file__)+os.sep+'..')
import PySourceInfo_check_tests #@UnresolvedImport
fpn = pysourceinfo.PySourceInfo.getModuleFilePathName(PySourceInfo_check_tests)
fm = PySourceInfo_check_tests.check_callback(pysourceinfo.PySourceInfo.getCallerModule,1)
fx = pysourceinfo.PySourceInfo.getModuleFilePathName(fm)
assert os.path.normpath(fx) == fpn
if len(fx) >4:
assert fx[-4:] == '.pyc' # just ignore first call
[ sys.path.pop() for x in range(len(sys.path)) ] #@UnusedVariable
sys.path.extend(_s)
[docs] def testCase002(self):
import sys
_s=sys.path[:]
sys.path.insert(0,os.path.dirname(__file__)+os.sep+'..')
import PySourceInfo_check_tests #@UnresolvedImport
fpn = os.path.abspath(os.path.normpath(__file__))
# if fpn[-3:] == '.py': # first call
# fpn += 'c'
fm = PySourceInfo_check_tests.check_callback(pysourceinfo.PySourceInfo.getCallerModule,2)
fx = pysourceinfo.PySourceInfo.getModuleFilePathName(fm)
assert os.path.normpath(fx) == fpn
if len(fx) >4:
assert fx[-4:] == '.pyc' # just ignore first call
[ sys.path.pop() for x in range(len(sys.path)) ] #@UnusedVariable
sys.path.extend(_s)
[docs] def testCase003(self):
import sys
_s=sys.path[:]
sys.path.insert(0,os.path.dirname(__file__)+os.sep+'..')
import PySourceInfo_check_tests #@UnresolvedImport
fm = PySourceInfo_check_tests.check_callback(pysourceinfo.PySourceInfo.getCallerModule,3)
fx = pysourceinfo.PySourceInfo.getModuleFilePathName(fm)
fx = os.path.basename(fx)
version = '{0}.{1}'.format(*sys.version_info[:2])
if version == '2.6': # pragma: no cover
assert os.path.basename(fx) == 'unittest.pyc'
elif version == '2.7': # pragma: no cover
assert os.path.basename(fx) == 'case.pyc'
else:
assert False
if len(fx) >4:
assert fx[-4:] == '.pyc' # just ignore first call
[ sys.path.pop() for x in range(len(sys.path)) ] #@UnusedVariable
sys.path.extend(_s)
if __name__ == '__main__':
unittest.main()