From c023b96f60cb6ba0f8631a060ed49b25e136d7ad Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Wed, 14 May 2014 21:16:13 +0300 Subject: [PATCH] os.path: Implement isdir(). --- os.path/os/path.py | 8 ++++++++ os.path/test_path.py | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/os.path/os/path.py b/os.path/os/path.py index aacd3277..f34b5bd3 100644 --- a/os.path/os/path.py +++ b/os.path/os/path.py @@ -27,3 +27,11 @@ def exists(path): # TODO lexists = exists + +def isdir(path): + import stat + try: + mode = os.stat(path)[0] + return stat.S_ISDIR(mode) + except OSError: + return False diff --git a/os.path/test_path.py b/os.path/test_path.py index d0fd58fa..5cde0579 100644 --- a/os.path/test_path.py +++ b/os.path/test_path.py @@ -6,3 +6,10 @@ assert split("/") == ("/", "") assert split("/foo") == ("/", "foo") assert split("/foo/") == ("/foo", "") assert split("/foo/bar") == ("/foo", "bar") + +assert exists("test_path.py") +assert not exists("test_path.py--") + +assert isdir("os") +assert not isdir("os--") +assert not isdir("test_path.py")