-
Notifications
You must be signed in to change notification settings - Fork 136
/
test_cmdparser.py
executable file
·100 lines (83 loc) · 3.46 KB
/
test_cmdparser.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
udocker unit tests: CmdParser
"""
from unittest import TestCase, main
from udocker.cmdparser import CmdParser
import collections
collections.Callable = collections.abc.Callable
class CmdParserTestCase(TestCase):
"""Test CmdParserTestCase() command line interface."""
def test_01__init(self):
"""Test01 CmdParser() Constructor."""
cmdp = CmdParser()
self.assertEqual(cmdp._argv, "")
self.assertIsInstance(cmdp._argv_split, dict)
self.assertIsInstance(cmdp._argv_consumed_options, dict)
self.assertIsInstance(cmdp._argv_consumed_params, dict)
self.assertEqual(cmdp._argv_split['CMD'], "")
self.assertEqual(cmdp._argv_split['GEN_OPT'], [])
self.assertEqual(cmdp._argv_split['CMD_OPT'], [])
self.assertEqual(cmdp._argv_consumed_options['GEN_OPT'], [])
self.assertEqual(cmdp._argv_consumed_options['CMD_OPT'], [])
self.assertEqual(cmdp._argv_consumed_params['GEN_OPT'], [])
self.assertEqual(cmdp._argv_consumed_params['CMD_OPT'], [])
def test_02_parse(self):
"""Test02 CmdParser().parse()."""
cmdp = CmdParser()
argv = ["udocker", "run", "--bindhome", "--hostauth", "--hostenv",
"-v", "/sys", "-v", "/proc", "-v", "/var/run", "-v", "/dev",
"--user=jorge", "--dri", "myfed", "firefox"]
status = cmdp.parse(argv)
self.assertTrue(status)
argv = ""
status = cmdp.parse(argv)
self.assertFalse(status)
def test_03_missing_options(self):
"""Test03 CmdParser().missing_options()."""
cmdp = CmdParser()
argv = ["udocker", "run", "--bindhome", "--hostauth", "--hostenv",
"-v", "/sys", "-v", "/proc", "-v", "/var/run", "-v", "/dev",
"--user=jorge", "--dri", "myfed", "firefox"]
cmdp.parse(argv)
out = cmdp.missing_options()
self.assertIsInstance(out, list)
def test_04_get(self):
"""Test04 CmdParser().get()."""
argv = ["udocker", "--debug", "run", "--bindhome", "--hostauth",
"--hostenv", "-v", "/sys", "-v", "/proc", "-v",
"/var/run", "-v", "/dev", "--user=jorge", "--dri",
"myfed", "firefox"]
cmdp = CmdParser()
cmdp.parse(argv)
out = cmdp.get("xyz")
self.assertIsNone(out)
argv = ["udocker", "--debug", "run", "--bindhome",
"-v", "/sys", "--user=jorge", "--dri", "myfed", "firefox"]
cmdp = CmdParser()
cmdp.parse(argv)
out = cmdp.get("--debug", "GEN_OPT", True)
self.assertTrue(out)
out = cmdp.get("", "CMD", True)
self.assertTrue(out, "run")
out = cmdp.get("--bindhome", "CMD_OPT", True)
self.assertEqual(out, [True])
argv = ["udocker", "export", "-o", "cont.tar", "12345"]
cmdp = CmdParser()
cmdp.parse(argv)
out = cmdp.get("", "CMD", True)
cmdp.get("-o")
tarfile = cmdp.get("P1")
container_id = cmdp.get("P2")
self.assertTrue(out, "export")
self.assertTrue(tarfile, "cont.tar")
self.assertTrue(container_id, "12345")
# def test_05_declare_options(self):
# """Test05 CmdParser().declare_options()."""
# def test_06__get_option(self):
# """Test06 CmdParser()._get_option()."""
# def test_07__get_param(self):
# """Test07 CmdParser()._get_param()."""
if __name__ == '__main__':
main()