forked from lowks/pythonpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_pythonpy.py
More file actions
51 lines (42 loc) · 2.22 KB
/
test_pythonpy.py
File metadata and controls
51 lines (42 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import unittest
from subprocess import check_output
class TestPythonPy(unittest.TestCase):
def test_empty(self):
self.assertEqual(check_output(['py']), b'')
def test_numbers(self):
self.assertEqual(check_output(['py', '3 * 4.5']), b'13.5\n')
def test_range(self):
self.assertEqual(check_output(['py', 'range(3)']), b'0\n1\n2\n')
def test_split_input(self):
self.assertEqual(check_output(["""echo a,b | py -x 'x[1]' --si ,"""], shell=True), b'b\n')
def test_split_output(self):
self.assertEqual(check_output(["""echo abc | py -x x --si '' --so ','"""], shell=True), b'a,b,c\n')
def test_ignore_errors(self):
self.assertEqual(check_output("""echo a | py -x --i 'None.None'""", shell=True), b'')
self.assertEqual(check_output("""echo a | py -fx --i 'None.None'""", shell=True), b'')
def test_statements(self):
self.assertEqual(check_output("""py -c 'a=5' -C 'print(a)'""", shell=True), b'5\n')
self.assertEqual(check_output("""echo 3 | py -c 'a=5' -x x -C 'print(a)'""", shell=True), b'3\n5\n')
def test_imports(self):
module_commands = ["math.ceil(2.5)",
"base64.b64encode('data to be encoded')",
"calendar.weekday(1955, 11, 5)",
"csv.list_dialects()",
"datetime.timedelta(hours=-5)",
"hashlib.sha224(\"Nobody inspects the spammish repetition\").hexdigest()",
"glob.glob('*')",
"itertools.product(['a','b'], [1,2])",
"json.dumps([1,2,3,{'4': 5, '6': 7}], separators=(',',':'))",
"os.name",
"random.randint(0, 1000)",
"re.compile('[a-z]').findall('abcd')",
"shutil.get_archive_formats()",
"tempfile.gettempdir()",
"uuid.uuid1()",
"math",
"[math]",
]
for command in module_commands:
check_output("py %r" % command, shell=True)
if __name__ == '__main__':
unittest.main()