(self)
| 85 | assert "1111" in sys.stdout.getvalue() |
| 86 | |
| 87 | def test_console_requests(self): |
| 88 | with self.interpreter() as interpreter: |
| 89 | from _pydev_bundle.pydev_console_utils import CodeFragment |
| 90 | |
| 91 | interpreter.add_exec(CodeFragment("class Foo:\n CONSTANT=1\n")) |
| 92 | interpreter.add_exec(CodeFragment("foo=Foo()")) |
| 93 | interpreter.add_exec(CodeFragment("foo.__doc__=None")) |
| 94 | interpreter.add_exec(CodeFragment("val = input()")) |
| 95 | interpreter.add_exec(CodeFragment("50")) |
| 96 | interpreter.add_exec(CodeFragment("print (val)")) |
| 97 | found = sys.stdout.getvalue().split() |
| 98 | try: |
| 99 | self.assertEqual(["50", "input_request"], found) |
| 100 | except: |
| 101 | try: |
| 102 | self.assertEqual(["input_request"], found) # IPython |
| 103 | except: |
| 104 | self.assertEqual(["50", "input_request"], found[1:]) # IPython 5.1 |
| 105 | self.assertTrue(found[0].startswith("Out")) |
| 106 | |
| 107 | comps = interpreter.getCompletions("foo.", "foo.") |
| 108 | self.assertTrue(("CONSTANT", "", "", "3") in comps or ("CONSTANT", "", "", "4") in comps, "Found: %s" % comps) |
| 109 | |
| 110 | comps = interpreter.getCompletions('"".', '"".') |
| 111 | self.assertTrue( |
| 112 | ("__add__", "x.__add__(y) <==> x+y", "", "3") in comps |
| 113 | or ("__add__", "", "", "4") in comps |
| 114 | or ("__add__", "x.__add__(y) <==> x+y\r\nx.__add__(y) <==> x+y", "()", "2") in comps |
| 115 | or ("__add__", "x.\n__add__(y) <==> x+yx.\n__add__(y) <==> x+y", "()", "2"), |
| 116 | "Did not find __add__ in : %s" % (comps,), |
| 117 | ) |
| 118 | |
| 119 | completions = interpreter.getCompletions("", "") |
| 120 | for c in completions: |
| 121 | if c[0] == "AssertionError": |
| 122 | break |
| 123 | else: |
| 124 | self.fail("Could not find AssertionError") |
| 125 | |
| 126 | completions = interpreter.getCompletions("Assert", "Assert") |
| 127 | for c in completions: |
| 128 | if c[0] == "RuntimeError": |
| 129 | self.fail("Did not expect to find RuntimeError there") |
| 130 | |
| 131 | assert ("__doc__", None, "", "3") not in interpreter.getCompletions("foo.CO", "foo.") |
| 132 | |
| 133 | comps = interpreter.getCompletions("va", "va") |
| 134 | assert ("val", "", "", "3") in comps or ("val", "", "", "4") in comps |
| 135 | |
| 136 | interpreter.add_exec(CodeFragment('s = "mystring"')) |
| 137 | |
| 138 | desc = interpreter.getDescription("val") |
| 139 | self.assertTrue( |
| 140 | desc.find("str(object) -> string") >= 0 |
| 141 | or desc == "'input_request'" |
| 142 | or desc.find("str(string[, encoding[, errors]]) -> str") >= 0 |
| 143 | or desc.find("str(Char* value)") >= 0 |
| 144 | or desc.find("str(object='') -> string") >= 0 |
nothing calls this directly
no test coverage detected