Skip to content

Commit 7c089a7

Browse files
Merge b68e3da into master
2 parents 78be090 + b68e3da commit 7c089a7

23 files changed

+214
-84
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def load_module_dict(filename: str) -> dict:
1313

1414

1515
name = "vien"
16-
constants = load_module_dict(f'{name}/constants.py')
16+
constants = load_module_dict(f'{name}/_constants.py')
1717

1818
readme = (Path(__file__).parent / 'README.md').read_text(encoding="utf-8")
1919
readme = "# " + readme.partition("\n#")[-1]

tests/test_arg_parser.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
# SPDX-FileCopyrightText: (c) 2021 Artëm IG <github.com/rtmigo>
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
14
import unittest
25
from pathlib import Path
36
from typing import List
47

58
from vien._common import is_windows
69

710
from tests.common import is_posix
8-
from vien.main import get_project_dir
9-
from vien.arg_parser import Parsed, Commands, items_after
11+
from vien._main import get_project_dir
12+
from vien._parsed_args import Parsed, Commands, items_after
1013

1114

1215
def windows_too(args: List[str]) -> List[str]:

tests/bash_runner_test.py renamed to tests/test_bash_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from timeit import default_timer as timer
99

1010
from tests.common import is_posix
11-
from vien.bash_runner import *
11+
from vien._bash_runner import *
1212
from tests.time_limited import TimeLimited
1313

1414

tests/test_call_funcs.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# SPDX-FileCopyrightText: (c) 2021 Artëm IG <github.com/rtmigo>
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
4+
import os
5+
import unittest
6+
7+
from vien._call_funcs import relative_fn_to_module_name, NotInnerPath, \
8+
relative_inner_path
9+
10+
11+
def rip(a: str, b: str) -> str:
12+
if os.name == 'posix':
13+
a = a.replace("W:", "")
14+
b = b.replace("W:", "")
15+
return relative_inner_path(a, b)
16+
17+
18+
class TestRelativeInnerPath(unittest.TestCase):
19+
20+
def assertEqualAnyslash(self, a: str, b: str):
21+
self.assertEqual(a.replace('\\', '/'),
22+
b.replace('\\', '/'))
23+
24+
def test_child(self):
25+
self.assertEqualAnyslash(
26+
rip('W:/abc/myProject/file.py', 'W:/abc/myProject'),
27+
'file.py')
28+
29+
def test_sub_child(self):
30+
self.assertEqualAnyslash(
31+
rip('W:/abc/myProject/pkg/sub/file.py',
32+
'W:/abc/myProject'),
33+
'pkg/sub/file.py')
34+
35+
@unittest.skipUnless(os.name == 'nt', "windows-specific")
36+
def test_sub_child_back(self):
37+
self.assertEqualAnyslash(
38+
rip('W:\\abc\\myProject\\pkg\\sub\\file.py',
39+
'W:\\abc\\myProject'),
40+
'pkg/sub/file.py')
41+
42+
def test_both_relative(self):
43+
self.assertEqualAnyslash(
44+
rip('myProject/pkg/sub/file.py',
45+
'myProject'),
46+
'pkg/sub/file.py')
47+
48+
def test_same(self):
49+
with self.assertRaises(NotInnerPath):
50+
rip('W:/abc/myProject/x', 'W:/abc/myProject/x'),
51+
52+
def test_swapped(self):
53+
with self.assertRaises(NotInnerPath):
54+
rip('W:/abc', 'W:/abc/myProject/x'),
55+
56+
@unittest.skipUnless(os.name == 'nt', "windows-specific")
57+
def test_swapped_backslash(self):
58+
with self.assertRaises(NotInnerPath):
59+
rip('W:\\abc', 'W:\\abc\\myProject\\x'),
60+
61+
def test_neighbor(self):
62+
with self.assertRaises(NotInnerPath):
63+
rip('W:/abc', 'W:/abc/myProject/x'),
64+
65+
66+
class TestFnToModuleName(unittest.TestCase):
67+
68+
def test_fwd(self):
69+
self.assertEqual(
70+
relative_fn_to_module_name('pkg/sub/module.py'),
71+
'pkg.sub.module')
72+
73+
def test_py_uppercase(self):
74+
self.assertEqual(
75+
relative_fn_to_module_name('pkg/sub/module.PY'),
76+
'pkg.sub.module')
77+
78+
def test_no_slashes(self):
79+
self.assertEqual(
80+
relative_fn_to_module_name('file.py'),
81+
'file')
82+
83+
@unittest.skipUnless(os.name == 'nt', "windows-specific")
84+
def test_back(self):
85+
self.assertEqual(
86+
relative_fn_to_module_name('pkg\\sub\\module.py'),
87+
'pkg.sub.module')
88+
89+
def test_no_py(self):
90+
with self.assertRaises(ValueError):
91+
relative_fn_to_module_name('pkg/sub/module')
92+
93+
def test_dots_ext(self):
94+
with self.assertRaises(ValueError):
95+
relative_fn_to_module_name('pkg/sub/module.ext.py')
96+
97+
def test_dots_parent(self):
98+
with self.assertRaises(ValueError):
99+
relative_fn_to_module_name('../sub/module.ext.py')
100+
101+
def test_dots_name(self):
102+
with self.assertRaises(ValueError):
103+
relative_fn_to_module_name('sub/.module.py')
104+
105+
106+
if __name__ == "__main__":
107+
unittest.main()

tests/test_call_parser.py

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,11 @@
1+
# SPDX-FileCopyrightText: (c) 2021 Artëm IG <github.com/rtmigo>
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
14
import unittest
25

3-
from tests.common import is_posix
4-
from vien.call_parser import ParsedCall
5-
6-
7-
# class TestOld(unittest.TestCase):
8-
# # remove?
9-
# def test_items_after(self):
10-
# self.assertEqual(list(items_after(['A', 'B', 'C'], 'A')),
11-
# ['B', 'C'])
12-
# self.assertEqual(list(items_after(['A', 'B', 'C'], 'B')),
13-
# ['C'])
14-
# self.assertEqual(list(items_after(['A', 'B', 'C'], 'C')),
15-
# [])
16-
# with self.assertRaises(LookupError):
17-
# list(items_after(['A', 'B', 'C'], 'X'))
18-
#
19-
# def test_call_pyfile(self):
20-
# self.assertEqual(
21-
# call_pyfile("vien -p zzz call -d file.py arg1".split()),
22-
# "file.py")
23-
# self.assertEqual(
24-
# call_pyfile("vien -p zzz call -d arg1 arg2".split()),
25-
# None)
26-
# self.assertEqual(
27-
# call_pyfile("vien -p zzz call -d File.PY arg1".split()),
28-
# "File.PY")
29-
# self.assertEqual(
30-
# call_pyfile("vien aaa.py bbb.py call -d ccc.py arg1".split()),
31-
# "ccc.py")
32-
from vien.exceptions import PyFileArgNotFoundExit
6+
from vien._parsed_call import ParsedCall
7+
8+
from vien._exceptions import PyFileArgNotFoundExit
339

3410

3511
class TestNew(unittest.TestCase):

tests/test_get_project_dir.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
# SPDX-FileCopyrightText: (c) 2021 Artëm IG <github.com/rtmigo>
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
14
import os
25
import unittest
36
from pathlib import Path
47

58
from tests.common import is_posix
69
from tests.test_arg_parser import windows_too
7-
from vien.main import get_project_dir
8-
from vien.exceptions import PyFileArgNotFoundExit
9-
from vien.arg_parser import Parsed
10+
from vien._main import get_project_dir
11+
from vien._exceptions import PyFileArgNotFoundExit
12+
from vien._parsed_args import Parsed
1013

1114

1215
def fix_paths(s: str):

tests/main_test.py renamed to tests/test_main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
from typing import List, Optional
1717

1818
from tests.test_arg_parser import windows_too
19-
from vien.arg_parser import Parsed
19+
from vien._parsed_args import Parsed
2020

2121
from vien._common import is_windows
2222

2323
from tests.common import is_posix
2424
from tests.time_limited import TimeLimited
2525
from vien import main_entry_point
26-
from vien.exceptions import ChildExit, VenvExistsExit, VenvDoesNotExistExit, \
26+
from vien._exceptions import ChildExit, VenvExistsExit, VenvDoesNotExistExit, \
2727
PyFileNotFoundExit, FailedToCreateVenvExit, CannotFindExecutableExit
2828

2929

tests/pythonpath_test.py renamed to tests/test_pythonpath.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
# SPDX-FileCopyrightText: (c) 2021 Artëm IG <github.com/rtmigo>
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
14
import os
25
import unittest
36

4-
from vien.main import _insert_into_pythonpath
7+
from vien._main import _insert_into_pythonpath
58

69

710
@unittest.skipUnless(os.name == 'posix', "posix colons format")

tests/systems_test.py renamed to tests/test_systems.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# SPDX-FileCopyrightText: (c) 2021 Artëm IG <github.com/rtmigo>
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
14
import unittest
25

36
from vien._common import need_posix, UnexpectedOsError, need_windows

tests/vien_dir_test.py renamed to tests/test_vien_dir.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
# SPDX-FileCopyrightText: (c) 2021 Artëm IG <github.com/rtmigo>
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
14
import os
25
import unittest
36
from pathlib import Path
47

58
from tests.common import is_posix
6-
from vien.main import get_vien_dir
9+
from vien._main import get_vien_dir
710

811
@unittest.skipUnless(is_posix, "not POSIX")
912
class TestVenvsDir(unittest.TestCase):

0 commit comments

Comments
 (0)