From ddb542494117f67addf3d41ea8fe9a570adf9e90 Mon Sep 17 00:00:00 2001 From: "Martin A. Brown" Date: Mon, 29 Feb 2016 11:32:01 -0800 Subject: [PATCH] get 100% coverage on the utils.py module --- tests/test_utils.py | 16 +++++++++++++--- tldp/utils.py | 7 ++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 4c393c4..bd8c315 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -11,11 +11,10 @@ from tldptesttools import TestToolsFilesystem # -- SUT from tldp.utils import makefh, which, execute -from tldp.utils import statfiles, stem_and_ext +from tldp.utils import statfile, statfiles, stem_and_ext from tldp.utils import arg_isexecutable, isexecutable from tldp.utils import arg_isreadablefile, isreadablefile -from tldp.utils import arg_isdirectory -from tldp.utils import arg_isloglevel +from tldp.utils import arg_isdirectory, arg_isloglevel class Test_isexecutable_and_friends(unittest.TestCase): @@ -159,6 +158,17 @@ class Test_statfiles(unittest.TestCase): self.assertEquals(0, len(statinfo)) +class Test_statfile(TestToolsFilesystem): + + def test_statfile_bogustype(self): + with self.assertRaises(TypeError) as ecm: + statfile(0) + + def test_statfile_enoent(self): + f = ntf(dir=self.tempdir) + st = statfile(f.name + '-ENOENT_TEST') + + class Test_stem_and_ext(unittest.TestCase): def test_stem_and_ext_final_slash(self): diff --git a/tldp/utils.py b/tldp/utils.py index a37e6a6..3106740 100644 --- a/tldp/utils.py +++ b/tldp/utils.py @@ -209,14 +209,11 @@ def makefh(thing): def statfile(name): '''return posix.stat_result (or None) for a single file name''' try: - st = os.stat(name) + st = os.lstat(name) except OSError as e: if e.errno != errno.ENOENT: raise e - if os.path.islink(name): - st = os.lstat(name) - else: - st = None + st = None return st