Esempio n. 1
0
def test_process_item_error():
    with capture_log_output(mod.__name__) as log:
        results = set(mod.Pool().imap_unordered(one_over, [-1, 0, 1]))
    logs = log.get_output()
    eq(logs, Regex("error processing item in worker"))
    eq(logs, Regex("ZeroDivisionError"))
    eq(results, {-1, 1})
Esempio n. 2
0
    def test_time_limit_errors(self):
        output = str(self.output)
        eq(output, Regex(r"test1 took too long: 0:00:00\.0[1-9]"))
        eq(output, Regex(r"run time limit \(0\.051\) exceeded: 0\.0[5-9]"))

        # NOTE tearDownClass is not limited by class patch
        eq(output, Regex(r"teardown time limit \(0\.05\) exceeded: 0\.0[5-9]"))
Esempio n. 3
0
def test_form_linking_multiple_case_types():
    factory = AppFactory(build_version='2.9.0')
    m0, m0f0 = factory.new_basic_module('m0', 'frog')
    factory.form_opens_case(m0f0)

    m1, m1f0 = factory.new_basic_module('m1', 'frog')
    factory.form_requires_case(m1f0)
    m1.search_config.additional_case_types = ['tadpole']

    m0f0.post_form_workflow = WORKFLOW_FORM
    m0f0.form_links = [
        FormLink(form_id=m1f0.unique_id),
    ]

    suite = factory.app.create_suite()
    print(suite.decode('utf8'))

    # ensure that target datum contains both case types
    datum = extract_xml_partial(suite,
                                "./entry[2]/session/datum[@id='case_id']",
                                wrap=False).decode('utf8')
    eq(datum, Regex(r"\[@case_type='frog' or @case_type='tadpole'\]"))

    expected_stack = """
    <partial>
      <create>
        <command value="'m1'"/>
        <datum id="case_id" value="instance('commcaresession')/session/data/case_id_new_frog_0"/>
        <command value="'m1-f0'"/>
      </create>
    </partial>"""
    assert_xml_partial_equal(expected_stack, suite, "./entry[1]/stack/create")
Esempio n. 4
0
async def test_ag_not_installed():
    with tempdir() as tmp:
        command = "ag x xxxx"
        editor = FakeEditor(join(tmp, "file"))
        editor.ag_path = ag_path = join(tmp, "ag")
        result = await do_command(command, editor)
        eq(result["type"], "error")
        eq(result["message"], Regex(f"{ag_path} not found. "))
Esempio n. 5
0
async def test_ag_error():
    with tempdir() as tmp:
        command = "ag x xxxx"
        editor = FakeEditor(join(tmp, "file"))
        result = await do_command(command, editor)
        item, = result["items"]
        eq(item["description"], Regex("No such file or directory:"))
        eq(result["value"], command)
        assert "filter_results" not in result, result
Esempio n. 6
0
 def test_middleware_reports_slow_function_view_with_timer(
         self, notify_exception, add_breadcrumb):
     res = self.client.get('/slow_function')
     self.assertEqual(res.status_code, 200)
     notify_exception.assert_called_once()
     add_breadcrumb.assert_has_calls([
         mock.call(category="timing",
                   message=Regex(r"^sleep: 0.\d+"),
                   level="info")
     ])
Esempio n. 7
0
def test_profile_contextmanager():
    output = StringIO()
    args = []

    def func(arg):
        with profile(stream=output):
            args.append(arg)

    func(1)
    eq(args, [1])
    eq(output.getvalue(), Regex(r"\{method 'append' of 'list' objects\}"))
Esempio n. 8
0
def test_profile_decorator_with_options():
    output = StringIO()
    args = []

    @profile(stream=output)
    def func(arg):
        args.append(arg)

    func(1)
    eq(args, [1])
    eq(output.getvalue(), Regex(r"test_decorators.py:\d+\(func\)"))
Esempio n. 9
0
def test_profile_decorator():
    output = StringIO()
    args = []

    @profile
    def func(arg):
        args.append(arg)

    with patch.object(sys.stderr, "write", output.write):
        func(1)
    eq(args, [1])
    eq(output.getvalue(), Regex(r"test_decorators.py:\d+\(func\)"))
Esempio n. 10
0
 async def test(command, items, opts=None, **editor_props):
     editor = FakeEditor(join(tmp, "dir/file"), tmp)
     for name, val in editor_props.items():
         setattr(editor, name, val)
     result = await do_command(command, editor)
     actual_items = [
         f"{x.get('filepath', '')[len(tmp):]:<26} "
         f"{x.get('detail', ''):<15} {x['label']}"
         f"{(' ' + x['description']) if 'description' in x else ''}"
         for x in result["items"]
     ]
     assert_same_items(actual_items, items)
     discard = {"items", "type"}
     actual_opts = {k: v for k, v in result.items() if k not in discard}
     if opts is None:
         opts = {
             "filter_results": True,
             "placeholder": Regex("^ag "),
             "value": None,
         }
     eq(actual_opts, opts)
Esempio n. 11
0
def test_class_decorator_should_not_catch_unfiltered_teardown_warning():
    @filter_warnings("default", "message", DeprecationWarning)
    class Test(TestCase):
        @classmethod
        def setUpClass(cls):
            log.append("setup")
            super().setUpClass()

        @classmethod
        def tearDownClass(cls):
            warnings.warn("fail")
            log.append("teardown")

        def runTest(self):
            log.append("test")  # should not get here

    log = []
    result = TestResult()
    TestSuite([Test()]).run(result)
    eq(str(result.errors), Regex(r" in tearDownClass\\n .*Warning: fail"), result)
    eq(log, ["setup", "test"])
Esempio n. 12
0
 def get_expected_structure(self, with_version=False):
     xmlns = Regex(r"http://openrosa.org/formdesigner/[a-fA-F0-9\-]{36}")
     unique_id = Regex(r"[a-f0-9]{32}")
     questions = [{
         "comment": None,
         "constraint": None,
         "group": None,
         "hashtagValue": "#form/name",
         "is_group": False,
         "label": "name",
         "label_ref": "name-label",
         "relevant": None,
         "repeat": None,
         "required": False,
         "setvalue": None,
         "tag": "input",
         "translations": {
             "en": "name"
         },
         "type": "Text",
         "value": "/data/name"
     }]
     if with_version:
         versions = [{
             "id":
             unique_id,
             "build_comment":
             None,
             "built_on":
             Regex(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{6}Z"),
             "is_released":
             False,
             "version":
             1
         }]
     else:
         versions = []
     return {
         "name":
         "API App",
         "resource_uri":
         "",
         "version":
         1,
         "build_comment":
         None,
         "built_from_app_id":
         None,
         "built_on":
         None,
         "id":
         unique_id,
         "versions":
         versions,
         "is_released":
         False,
         "modules": [{
             "name": {
                 "en": "open_case module"
             },
             "unique_id":
             "open_case_module",
             "case_type":
             "house",
             "case_properties": ["name"],
             "forms": [{
                 "unique_id": "open_case_form_0",
                 "name": {
                     "en": "open_case form 0"
                 },
                 "questions": questions,
                 "xmlns": xmlns
             }],
         }, {
             "name": {
                 'en': 'update_case module'
             },
             "unique_id":
             "update_case_module",
             "case_type":
             "person",
             "case_properties": ["name"],
             "forms": [{
                 "unique_id": "update_case_form_0",
                 "name": {
                     "en": "update_case form 0"
                 },
                 "questions": questions,
                 "xmlns": xmlns
             }],
         }],
     }
Esempio n. 13
0
async def test_syntax_error():
    editor = FakeEditor(text='print "not with python 3"')
    try:
        await do_command("python", editor)
    except ProcessError as err:
        eq(str(err), Regex("SyntaxError"))
Esempio n. 14
0
 def test_time_limit(self):
     output = str(self.output)
     eq(output, Regex(r"teardown time limit \(0\.05\) exceeded: 0\.0[5-9]"))
Esempio n. 15
0
 def test_time_limit(self):
     output = str(self.output)
     eq(output, Regex(r"runTest took too long: 0:00:00.0[6-9]"))
Esempio n. 16
0
 def test_time_limit1(self):
     output = str(self.output)
     eq(output, Regex(r"run time limit \(0\.051\) exceeded: 0\.0[5-9]"))