File: TestImport.py

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (74 lines) | stat: -rw-r--r-- 3,234 bytes parent folder | download | duplicates (10)
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
"""Test custom import command to import files by path."""


import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class ImportTestCase(TestBase):
    @add_test_categories(["pyapi"])
    @no_debug_info_test
    def test_import_command(self):
        """Import some Python scripts by path and test them"""
        self.run_test()

    def run_test(self):
        """Import some Python scripts by path and test them."""

        # This is the function to remove the custom commands in order to have a
        # clean slate for the next test case.
        def cleanup():
            self.runCmd("command script delete foo2cmd", check=False)
            self.runCmd("command script delete foocmd", check=False)
            self.runCmd("command script delete foobarcmd", check=False)
            self.runCmd("command script delete barcmd", check=False)
            self.runCmd("command script delete barothercmd", check=False)
            self.runCmd("command script delete TPcommandA", check=False)
            self.runCmd("command script delete TPcommandB", check=False)

        # Execute the cleanup function during test case tear down.
        self.addTearDownHook(cleanup)

        self.runCmd("command script import ./foo/foo.py --allow-reload")
        self.runCmd("command script import ./foo/foo2.py --allow-reload")
        self.runCmd("command script import ./foo/bar/foobar.py --allow-reload")
        self.runCmd("command script import ./bar/bar.py --allow-reload")

        self.expect(
            "command script import ''",
            error=True,
            startstr="error: module importing failed: empty path",
        )
        self.expect(
            "command script import ./nosuchfile.py",
            error=True,
            startstr="error: module importing failed: invalid pathname './nosuchfile.py'",
        )
        self.expect(
            "command script import ./nosuchfolder/",
            error=True,
            startstr="error: module importing failed: invalid pathname './nosuchfolder/'",
        )
        self.expect("command script import ./foo/foo.py", error=False)
        self.runCmd("command script import --allow-reload ./thepackage")
        self.expect("TPcommandA", substrs=["hello world A"])
        self.expect("TPcommandB", substrs=["hello world B"])

        self.runCmd("script import dummymodule")
        self.expect("command script import ./dummymodule.py", error=False)
        self.expect(
            "command script import --allow-reload ./dummymodule.py", error=False
        )

        self.runCmd("command script add -f foo.foo_function foocmd")
        self.runCmd("command script add -f foobar.foo_function foobarcmd")
        self.runCmd("command script add -f bar.bar_function barcmd")
        self.expect("foocmd hello", substrs=["foo says", "hello"])
        self.expect("foo2cmd hello", substrs=["foo2 says", "hello"])
        self.expect("barcmd hello", substrs=["barutil says", "bar told me", "hello"])
        self.expect(
            "barothercmd hello", substrs=["barutil says", "bar told me", "hello"]
        )
        self.expect("foobarcmd hello", substrs=["foobar says", "hello"])