Example #1
0
    def test_against_files(self):
        @register_repr(weakref.ref)
        def repr_weakref(*_):
            return '<weakref>'

        ids = get_call_ids(golden_script.main)
        calls = [session.query(Call).filter_by(id=c_id).one() for c_id in ids]

        def normalise_addresses(string):
            return re.sub(r'at 0x\w+>', 'at 0xABC>', string)

        data = [
            dict(
                arguments=byteify(
                    json.loads(normalise_addresses(call.arguments))),
                return_value=byteify(normalise_addresses(call.return_value)),
                exception=call.exception,
                traceback=call.traceback,
                data=normalise_call_data(normalise_addresses(call.data)),
            ) for call in calls
        ]
        version = re.match(r'\d\.\d', sys.version).group()
        path = os.path.join(os.path.dirname(__file__), 'golden-files', version,
                            'calls.json')

        if 1:  # change to 0 to write new data instead of reading and testing
            self.assertEqual(data, byteify(file_to_json(path)))
        else:
            json_to_file(data, path)
Example #2
0
    def test_against_files(self):
        @register_repr(weakref.ref)
        def repr_weakref(*_):
            return '<weakref>'

        def normalise_addresses(string):
            return re.sub(r'at 0x\w+>', 'at 0xABC>', string)

        data = [
            dict(
                arguments=byteify(
                    json.loads(normalise_addresses(call.arguments))),
                return_value=byteify(normalise_addresses(call.return_value)),
                exception=call.exception,
                traceback=call.traceback,
                data=normalise_call_data(normalise_addresses(call.data)),
                function=dict(
                    name=byteify(call.function.name),
                    html_body=byteify(call.function.html_body),
                    lineno=call.function.lineno,
                    data=byteify(json.loads(call.function.data)),
                ),
            ) for call in golden_calls
        ]
        version = re.match(r'\d\.\d', sys.version).group()
        path = os.path.join(os.path.dirname(__file__), 'golden-files', version,
                            'calls.json')

        if 1:  # change to 0 to write new data instead of reading and testing
            self.assertEqual(data, byteify(file_to_json(path)))
        else:
            json_to_file(data, path)
Example #3
0
    def test_against_files(self):
        @register_repr(weakref.ref)
        def repr_weakref(*_):
            return '<weakref>'

        def normalise_addresses(string):
            return re.sub(r'at 0x\w+>', 'at 0xABC>', string)

        for name, calls in golden_calls.items():
            data = [
                dict(
                    arguments=byteify(
                        json.loads(normalise_addresses(call.arguments))),
                    return_value=byteify(
                        normalise_addresses(str(call.return_value))),
                    exception=call.exception,
                    traceback=call.traceback,
                    data=normalise_call_data(normalise_addresses(call.data)),
                    function=dict(
                        name=byteify(call.function.name),
                        html_body=byteify(call.function.html_body),
                        lineno=call.function.lineno,
                        data=byteify(json.loads(call.function.data)),
                    ),
                ) for call in calls
            ]
            version = PYPY * 'pypy' + sys.version[:3]
            path = os.path.join(os.path.dirname(__file__), 'golden-files',
                                version, name + '.json')

            if 1:  # change to 0 to write new data instead of reading and testing
                self.assertEqual(data, byteify(file_to_json(path)))
            else:
                with open(path, 'w') as f:
                    json.dump(data, f, indent=2, sort_keys=True)
Example #4
0
def frontend_terms():
    for key, value in file_to_json(frontend_src /
                                   "english_terms.json").items():
        translation = t.get(f"frontend.{key}", value)

        if "\n" in translation:
            value = markdown(translation)
        else:
            value = unwrapped_markdown(translation)

        result = new_tab_links(value)
        if value != result:
            assert key.startswith("question_wizard_")

        yield key, result
Example #5
0
def main():
    chapters = list(load_chapters())
    global page_link
    for page_slug, page in pages.items():
        page_link = "https://futurecoder.io/course/#" + page_slug
        entry(t.page_title(page_slug), page.raw_title, page_link)

        for step_name, text in zip(page.step_names, page.step_texts(raw=True)):
            step_msgid = t.step(page_slug, step_name)
            text_entry(t.step_text(page_slug, step_name), text)
            if step_name == "final_text":
                continue

            step = page.get_step(step_name)
            comments = [search_link(step_msgid)]
            for message_step in step.messages:
                msgid = t.message_step_text(step, message_step)
                text = message_step.raw_text
                text_entry(msgid, text, comments)

            for special_message in get_special_messages(step):
                text_entry(t.special_message_text(step, special_message),
                           special_message.text)

            for i, hint in enumerate(step.hints):
                msgid = t.hint(step, i)
                text_entry(msgid, hint, comments)

            for i, disallowed in enumerate(step.disallowed):
                label = disallowed.label
                message = disallowed.message
                if label and not label[0] == label[-1] == '`':
                    entry(t.disallowed_label(step, i), label)
                if message:
                    entry(t.disallowed_message(step, i), message)

            if step.auto_translate_program:
                for _, node_text in t.get_code_bits(step.program):
                    code_bits[node_text].add(
                        f"{search_link(step_msgid)}\n\n{step.program}")
            else:
                entry(t.step_program(step), step.program,
                      search_link(step_msgid))

            if step.translate_output_choices:
                output_prediction_choices = get_predictions(
                    step)["choices"] or []
                for i, choice in enumerate(output_prediction_choices[:-1]):
                    if (not re.search(r"[a-zA-Z]", choice)
                            or choice in ("True", "False")):
                        continue
                    entry(t.prediction_choice(step, i), choice,
                          search_link(step_msgid))

    for code_bit, comments in code_bits.items():
        entry(
            t.code_bit(code_bit),
            code_bit,
            "\n\n------\n\n".join(sorted(comments)),
        )

    for message_cls, message_format in linting.MESSAGES.items():
        entry(t.pyflakes_message(message_cls), message_format.strip())

    for chapter in chapters:
        entry(t.chapter_title(chapter["slug"]), chapter["title"])

    for key, value in file_to_json(frontend_src /
                                   "english_terms.json").items():
        entry(f"frontend.{key}", value)

    entry(
        "output_predictions.Error",
        "Error",
        "Special choice at the end of all output prediction multiple choice questions",
    )

    for key, value in t.misc_terms():
        entry(t.misc_term(key), value)

    po.sort(key=lambda e: e.msgid)
    po.save(str(this_dir / "english.po"))
    po.save_as_mofile(str(this_dir / "locales/en/LC_MESSAGES/futurecoder.mo"))

    t.codes_path.write_text(json.dumps(code_blocks))
Example #6
0
def test_apispec():
    response = flask_client.get("/apispec_1.json")
    print(response.data)
    assert response.json == file_to_json(folder / "apispec.json")