add function stem_and_ext to the utils

This commit is contained in:
Martin A. Brown 2016-02-19 00:54:16 -08:00
parent d7fac8d65f
commit f200c0efc2
2 changed files with 19 additions and 1 deletions

View File

@ -10,7 +10,7 @@ from tldptesttools import TestToolsFilesystem
# -- SUT
from tldp.utils import makefh, which, execute
from tldp.utils import statfiles
from tldp.utils import statfiles, stem_and_ext
class Test_execute(TestToolsFilesystem):
@ -105,6 +105,19 @@ class Test_statfiles(unittest.TestCase):
self.assertEquals(0, len(statinfo))
class Test_stem_and_ext(unittest.TestCase):
def test_stem_and_ext_final_slash(self):
r0 = stem_and_ext('/h/q/t/z/Frobnitz-HOWTO')
r1 = stem_and_ext('/h/q/t/z/Frobnitz-HOWTO/')
self.assertEqual(r0, r1)
def test_stem_and_ext_rel_abs(self):
r0 = stem_and_ext('/h/q/t/z/Frobnitz-HOWTO')
r1 = stem_and_ext('Frobnitz-HOWTO/')
self.assertEqual(r0, r1)
class Test_att_statinfo(unittest.TestCase):
def test_max_mtime(self):

View File

@ -25,6 +25,11 @@ def getLogger(**opts):
logger = getLogger()
def stem_and_ext(name):
'''return (stem, ext) for any relative or absolute filename'''
return os.path.splitext(os.path.basename(os.path.normpath(name)))
def execute(cmd, stdin=None, stdout=None, stderr=None,
logdir=None, env=os.environ):
'''(yet another) wrapper around subprocess.Popen()