from doctest import testfile
from os import environ
from sys import argv
from sys import exit

import responses


def _setup():
    environ["FRONTEND_URL"] = "https://example.com/frontend"
    environ["BACKEND_URL"] = "https://example.com/backend"
    responses.add(
        responses.GET,
        "http://api.com/users/1/",
        json={"id": 1, "name": "John", "surname": "Doe"},
    )
    responses.start()


def _main():
    markdown_files = argv[1:]
    exit_code = 0
    for markdown_file in markdown_files:
        failed, attempted = testfile(markdown_file, module_relative=False)
        exit_code += failed
    exit(exit_code)


if __name__ == "__main__":  # pragma: no branch
    _setup()
    _main()
