def __init__(self): app = AttrDict({"config": AttrDict()}) env = AttrDict({"app": app}) settings = AttrDict({"env": env}) reporter = Reporter('', 0, 100) self.document = AttrDict({"settings": settings, "reporter": reporter})
def test_validate_config(): config = AttrDict({ "source_link_target": "Sphinx", "github_username": "******", "github_repository": "sphinx-toolbox", "rst_prolog": '', }) validate_config(None, config) # type: ignore assert config == { "source_link_target": "sphinx", "github_username": "******", "github_repository": "sphinx-toolbox", "github_url": RequestsURL("https://github.com/domdfcoding/sphinx-toolbox"), "github_source_url": RequestsURL( "https://github.com/domdfcoding/sphinx-toolbox/blob/master"), "github_issues_url": RequestsURL("https://github.com/domdfcoding/sphinx-toolbox/issues"), "github_pull_url": RequestsURL("https://github.com/domdfcoding/sphinx-toolbox/pull"), "rst_prolog": "\n\n.. |nbsp| unicode:: 0xA0\n :trim:", } config = AttrDict({ "source_link_target": "Sphinx", "github_username": None, "github_repository": "sphinx-toolbox", }) with pytest.raises(MissingOptionError, match="The 'github_username' option is required."): validate_config(None, config) # type: ignore config = AttrDict({ "source_link_target": "Sphinx", "github_username": "******", "github_repository": None, }) with pytest.raises(MissingOptionError, match="The 'github_repository' option is required."): validate_config(None, config) # type: ignore config = AttrDict({ "source_link_target": "bananas", "github_username": "******", "github_repository": "sphinx-toolbox", }) with pytest.raises(InvalidOptionError, match="Invalid value for 'source_link_target'."): validate_config(None, config) # type: ignore
def __init__(self, github_issues_url): config = AttrDict({"github_pull_url": RequestsURL(github_issues_url)}) app = AttrDict({"config": config}) env = AttrDict({"app": app}) settings = AttrDict({"env": env}) reporter = Reporter('', 0, 100) self.document = AttrDict({"settings": settings, "reporter": reporter})
def __init__(self, tab_width: int): config = AttrDict({ "docutils_tab_width": tab_width, "github_username": "******", "github_repository": "hello_world", "conda_channels": [], }) app = AttrDict(extensions=[ "sphinx_toolbox.installation", "sphinx_toolbox.github", ]) super().__init__({"config": config, "app": app})
def test_missing_repo(): directive = SimpleNamespace() directive.env = SimpleNamespace() directive.env.app = AttrDict( extensions=["sphinx_toolbox.sidebar_links", "sphinx_toolbox.github"]) directive.env.config = AttrDict({"github_username": "******"}) with pytest.raises( ValueError, match="'github_repository' has not been set in 'conf.py'!"): sidebar_links.SidebarLinksDirective.process_github_option( directive) # type: ignore
def test_missing_options(): config = AttrDict({ "github_username": "******", "github_repository": None, }) with pytest.raises(MissingOptionError, match="The 'github_repository' option is required."): github.validate_config('', config) # type: ignore config = AttrDict({ "github_username": None, "github_repository": "hello_world", }) with pytest.raises(MissingOptionError, match="The 'github_username' option is required."): github.validate_config('', config) # type: ignore
def test_source_link_target(target: str, expects: str): config = AttrDict({ "source_link_target": target, "github_username": "******", "github_repository": "sphinx-toolbox", "rst_prolog": '', }) validate_config(None, config) # type: ignore assert config.source_link_target == expects
def test_missing_extension(): directive = SimpleNamespace() directive.env = SimpleNamespace() directive.env.app = AttrDict(extensions=["sphinx_toolbox.sidebar_links"]) with pytest.raises( ValueError, match= "The 'sphinx_toolbox.github' extension is required for the :github: option but it is not enabled!" ): sidebar_links.SidebarLinksDirective.process_github_option( directive) # type: ignore
def __init__(self, source_link_target, github_source_url): config = AttrDict({ "source_link_target": source_link_target, "github_source_url": RequestsURL(github_source_url), }) app = AttrDict({ "config": config, "builder": AttrDict({ "get_relative_uri": lambda from_, to: to }) }) env = AttrDict({"app": app, "docname": ''}) settings = AttrDict({"env": env}) reporter = Reporter('', 0, 100) self.document = AttrDict({"settings": settings, "reporter": reporter})
def __init__(self, tab_width: int): config = AttrDict({"docutils_tab_width": tab_width}) super().__init__({"config": config})