-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set argv global variables from Python like tclsh would
EP-85
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 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,28 @@ | ||
import importlib | ||
import sys | ||
import unittest | ||
|
||
import tohil | ||
|
||
|
||
class TestArgGlobals(unittest.TestCase): | ||
def test_empty_argv(self): | ||
sys.argv = [] | ||
importlib.reload(tohil) | ||
self.assertEqual(tohil.call("info", "exists", "::argv"), 0) | ||
self.assertEqual(tohil.call("info", "exists", "::argv0"), 0) | ||
self.assertEqual(tohil.call("info", "exists", "::argc"), 0) | ||
|
||
def test_argv_blank(self): | ||
sys.argv = [""] | ||
importlib.reload(tohil) | ||
self.assertEqual(tohil.call("set", "::argv", to=list), []) | ||
self.assertEqual(tohil.call("set", "::argv0"), "") | ||
self.assertEqual(tohil.call("set", "::argc"), 0) | ||
|
||
def test_argv_multiple(self): | ||
sys.argv = ["script.py", "arg1", "arg2"] | ||
importlib.reload(tohil) | ||
self.assertEqual(tohil.call("set", "::argv", to=list), sys.argv[1:]) | ||
self.assertEqual(tohil.call("set", "::argv0"), "script.py") | ||
self.assertEqual(tohil.call("set", "::argc"), 2) |