1 """Test custom import command to import files by path.""" 2 3 import os, sys, time 4 import unittest2 5 import lldb 6 from lldbtest import * 7 8 class ImportTestCase(TestBase): 9 10 mydir = os.path.join("functionalities", "command_script", "import") 11 12 @python_api_test 13 @skipIfLinux # causes buildbot failures, skip until we can investigate it 14 def test_import_command(self): 15 """Import some Python scripts by path and test them""" 16 self.run_test() 17 18 def setUp(self): 19 # Call super's setUp(). 20 TestBase.setUp(self) 21 22 def run_test(self): 23 """Import some Python scripts by path and test them.""" 24 25 # This is the function to remove the custom commands in order to have a 26 # clean slate for the next test case. 27 def cleanup(): 28 self.runCmd('command script delete foo2cmd', check=False) 29 self.runCmd('command script delete foocmd', check=False) 30 self.runCmd('command script delete foobarcmd', check=False) 31 self.runCmd('command script delete barcmd', check=False) 32 self.runCmd('command script delete barothercmd', check=False) 33 self.runCmd('command script delete TPcommandA', check=False) 34 self.runCmd('command script delete TPcommandB', check=False) 35 36 # Execute the cleanup function during test case tear down. 37 self.addTearDownHook(cleanup) 38 39 self.runCmd("command script import ./foo/foo.py --allow-reload") 40 self.runCmd("command script import ./foo/foo2.py --allow-reload") 41 self.runCmd("command script import ./foo/bar/foobar.py --allow-reload") 42 self.runCmd("command script import ./bar/bar.py --allow-reload") 43 44 self.expect("command script import ./nosuchfile.py", 45 error=True, startstr='error: module importing failed') 46 self.expect("command script import ./nosuchfolder/", 47 error=True, startstr='error: module importing failed') 48 self.expect("command script import ./foo/foo.py", error=False) 49 50 self.runCmd("command script import --allow-reload ./thepackage") 51 self.expect("TPcommandA",substrs=["hello world A"]) 52 self.expect("TPcommandB",substrs=["hello world B"]) 53 54 self.runCmd("script import dummymodule") 55 self.expect("command script import ./dummymodule.py", error=False) 56 self.expect("command script import --allow-reload ./dummymodule.py", error=False) 57 58 self.runCmd("command script add -f foo.foo_function foocmd") 59 self.runCmd("command script add -f foobar.foo_function foobarcmd") 60 self.runCmd("command script add -f bar.bar_function barcmd") 61 self.expect("foocmd hello", 62 substrs = ['foo says', 'hello']) 63 self.expect("foo2cmd hello", 64 substrs = ['foo2 says', 'hello']) 65 self.expect("barcmd hello", 66 substrs = ['barutil says', 'bar told me', 'hello']) 67 self.expect("barothercmd hello", 68 substrs = ['barutil says', 'bar told me', 'hello']) 69 self.expect("foobarcmd hello", 70 substrs = ['foobar says', 'hello']) 71 72 73 if __name__ == '__main__': 74 import atexit 75 lldb.SBDebugger.Initialize() 76 atexit.register(lambda: lldb.SBDebugger.Terminate()) 77 unittest2.main() 78