1 """Test custom import command to import files by path."""
5 from lldbsuite
.test
.decorators
import *
6 from lldbsuite
.test
.lldbtest
import *
7 from lldbsuite
.test
import lldbutil
10 class ImportTestCase(TestBase
):
11 @add_test_categories(["pyapi"])
13 def test_import_command(self
):
14 """Import some Python scripts by path and test them"""
18 """Import some Python scripts by path and test them."""
20 # This is the function to remove the custom commands in order to have a
21 # clean slate for the next test case.
23 self
.runCmd("command script delete foo2cmd", check
=False)
24 self
.runCmd("command script delete foocmd", check
=False)
25 self
.runCmd("command script delete foobarcmd", check
=False)
26 self
.runCmd("command script delete barcmd", check
=False)
27 self
.runCmd("command script delete barothercmd", check
=False)
28 self
.runCmd("command script delete TPcommandA", check
=False)
29 self
.runCmd("command script delete TPcommandB", check
=False)
31 # Execute the cleanup function during test case tear down.
32 self
.addTearDownHook(cleanup
)
34 self
.runCmd("command script import ./foo/foo.py --allow-reload")
35 self
.runCmd("command script import ./foo/foo2.py --allow-reload")
36 self
.runCmd("command script import ./foo/bar/foobar.py --allow-reload")
37 self
.runCmd("command script import ./bar/bar.py --allow-reload")
40 "command script import ''",
42 startstr
="error: module importing failed: empty path",
45 "command script import ./nosuchfile.py",
47 startstr
="error: module importing failed: invalid pathname './nosuchfile.py'",
50 "command script import ./nosuchfolder/",
52 startstr
="error: module importing failed: invalid pathname './nosuchfolder/'",
54 self
.expect("command script import ./foo/foo.py", error
=False)
55 self
.runCmd("command script import --allow-reload ./thepackage")
56 self
.expect("TPcommandA", substrs
=["hello world A"])
57 self
.expect("TPcommandB", substrs
=["hello world B"])
59 self
.runCmd("script import dummymodule")
60 self
.expect("command script import ./dummymodule.py", error
=False)
62 "command script import --allow-reload ./dummymodule.py", error
=False
65 self
.runCmd("command script add -f foo.foo_function foocmd")
66 self
.runCmd("command script add -f foobar.foo_function foobarcmd")
67 self
.runCmd("command script add -f bar.bar_function barcmd")
68 self
.expect("foocmd hello", substrs
=["foo says", "hello"])
69 self
.expect("foo2cmd hello", substrs
=["foo2 says", "hello"])
70 self
.expect("barcmd hello", substrs
=["barutil says", "bar told me", "hello"])
72 "barothercmd hello", substrs
=["barutil says", "bar told me", "hello"]
74 self
.expect("foobarcmd hello", substrs
=["foobar says", "hello"])