-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
706 additions
and
174 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
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,60 @@ | ||
import unittest | ||
from pathlib import Path | ||
|
||
from vien.main import get_project_dir | ||
from vien.arg_parser import Parsed | ||
|
||
|
||
class TestProjectDir(unittest.TestCase): | ||
|
||
def test_run_short_left(self): | ||
pd = Parsed('-p a/b/c run python3 myfile.py'.split()) | ||
self.assertEqual(pd.project_dir_arg, 'a/b/c') | ||
|
||
def test_run_long_left(self): | ||
pd = Parsed('--project-dir a/b/c run python3 myfile.py'.split()) | ||
self.assertEqual(pd.project_dir_arg, 'a/b/c') | ||
|
||
def test_call_short_right(self): | ||
pd = Parsed('call -p a/b/c myfile.py'.split()) | ||
self.assertEqual(pd.project_dir_arg, 'a/b/c') | ||
|
||
def test_call_long_right(self): | ||
pd = Parsed('call --project-dir a/b/c myfile.py'.split()) | ||
self.assertEqual(pd.project_dir_arg, 'a/b/c') | ||
|
||
def test_call_short_left(self): | ||
pd = Parsed('-p a/b/c call myfile.py'.split()) | ||
self.assertEqual(pd.project_dir_arg, 'a/b/c') | ||
|
||
def test_call_long_left(self): | ||
pd = Parsed('--project-dir a/b/c call myfile.py'.split()) | ||
self.assertEqual(pd.project_dir_arg, 'a/b/c') | ||
|
||
def test_call_short_both(self): | ||
pd = Parsed('-p a/b/c call -p d/e/f myfile.py'.split()) | ||
self.assertEqual(pd.project_dir_arg, 'd/e/f') | ||
|
||
|
||
class TestCallOtherArgs(unittest.TestCase): | ||
|
||
def test_outdated_p(self): | ||
pd = Parsed('-p a/b/c call -p d/e/f myfile.py arg1 arg2'.split()) | ||
self.assertEqual(pd.args_to_python, ['myfile.py', 'arg1', 'arg2']) | ||
|
||
def test_p(self): | ||
pd = Parsed('-p a/b/c call -d myfile.py a b c'.split()) | ||
self.assertEqual(pd.args_to_python, ['-d', 'myfile.py', 'a', 'b', 'c']) | ||
|
||
def test_unrecoginzed(self): | ||
"""Unrecognized arguments that are NOT after the 'call' word.""" | ||
with self.assertRaises(SystemExit) as ce: | ||
Parsed('-labuda call myfile.py a b c'.split()) | ||
self.assertEqual(ce.exception.code, 2) | ||
|
||
|
||
|
||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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,33 @@ | ||
import unittest | ||
|
||
from vien.call_parser import items_after, call_pyfile | ||
|
||
|
||
class Test(unittest.TestCase): | ||
def test_items_after(self): | ||
self.assertEqual(list(items_after(['A', 'B', 'C'], 'A')), | ||
['B', 'C']) | ||
self.assertEqual(list(items_after(['A', 'B', 'C'], 'B')), | ||
['C']) | ||
self.assertEqual(list(items_after(['A', 'B', 'C'], 'C')), | ||
[]) | ||
with self.assertRaises(LookupError): | ||
list(items_after(['A', 'B', 'C'], 'X')) | ||
|
||
def test_call_pyfile(self): | ||
self.assertEqual( | ||
call_pyfile("vien -p zzz call -d file.py arg1".split()), | ||
"file.py") | ||
self.assertEqual( | ||
call_pyfile("vien -p zzz call -d arg1 arg2".split()), | ||
None) | ||
self.assertEqual( | ||
call_pyfile("vien -p zzz call -d File.PY arg1".split()), | ||
"File.PY") | ||
self.assertEqual( | ||
call_pyfile("vien aaa.py bbb.py call -d ccc.py arg1".split()), | ||
"ccc.py") | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Oops, something went wrong.