-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved logya.get_path to path.join.
- Loading branch information
Showing
3 changed files
with
66 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- coding: utf-8 -*- | ||
# Wrappers for functions from os.path. | ||
import os | ||
|
||
|
||
class PathResourceError(Exception): | ||
pass | ||
|
||
|
||
def join(basedir, *args, **kwargs): | ||
"""Get joined name relative to basedir for file or path name. | ||
Raises an exception if resource is required and doesn't exist. | ||
""" | ||
|
||
path = os.path.join(basedir, *args) | ||
if kwargs.get('required') and not os.path.exists(path): | ||
raise PathResourceError( | ||
'Resource at path {} does not exist.'.format(path)) | ||
return path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import unittest | ||
|
||
from logya import path | ||
|
||
|
||
class TestPath(unittest.TestCase): | ||
|
||
def test_join(self): | ||
self.assertEqual( | ||
'dir/file.ext', path.join('dir', 'file.ext')) | ||
self.assertEqual( | ||
'dir/subdir/file.ext', path.join('dir', 'subdir', 'file.ext')) | ||
|
||
def test_join_required_exists(self): | ||
self.assertEqual('tests', path.join('tests', required=True)) | ||
|
||
def test_join_required_not_exists(self): | ||
self.assertRaises(path.PathResourceError, | ||
path.join, | ||
*('dir', 'file.ext'), | ||
required=True) |