Skip to content

Commit 690c0e1

Browse files
committed
Support relative paths
1 parent b737ab9 commit 690c0e1

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

dbdiff/tests/test_utils.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
from dbdiff.utils import get_model_names
1+
import os
2+
3+
from dbdiff.utils import get_absolute_path, get_model_names
24

35
from django.contrib.auth.models import Group
46

57

68
def test_get_model_names():
79
assert get_model_names([Group, 'auth.user']) == ['auth.group', 'auth.user']
10+
11+
12+
def test_get_absolute_path_starting_with_dot():
13+
assert get_absolute_path('./foo') == os.path.join(
14+
os.path.abspath(os.path.dirname('__file__')),
15+
'foo',
16+
)

dbdiff/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ def get_absolute_path(path):
8383
if path.startswith('/'):
8484
return path
8585

86-
module_path = imp.find_module(path.split('/')[0])[1]
86+
if path.startswith('.'):
87+
module_path = '.'
88+
else:
89+
module_path = imp.find_module(path.split('/')[0])[1]
8790
return os.path.abspath(os.path.join(
8891
module_path,
8992
*path.split('/')[1:]

0 commit comments

Comments
 (0)