File: test_enumerate_fixtures.py

package info (click to toggle)
python-globus-sdk 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,172 kB
  • sloc: python: 35,227; sh: 44; makefile: 35
file content (69 lines) | stat: -rw-r--r-- 2,305 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import json
import re
import types

import pytest

import globus_sdk


def test_enumerate_fixtures_rejects_wrong_object_type(sphinx_runner, capsys):
    sphinx_runner.ensure_failure(
        ".. enumeratetestingfixtures:: globus_sdk.NullAuthorizer",
    )

    captured = capsys.readouterr()
    err_lines = captured.err.splitlines()

    test_line = None
    for line in err_lines:
        if "BaseClient" in line:
            test_line = line
            break
    else:
        pytest.fail("Didn't find 'BaseClient' in stderr")

    assert re.search(
        r"Expected <class '(\w+\.)+NullAuthorizer'> to be a subclass of BaseClient",
        test_line,
    )


# choose an arbitrary client to test against
def test_enumerate_fixtures_of_search_client(sphinx_runner):
    etree = sphinx_runner.to_etree(
        ".. enumeratetestingfixtures:: globus_sdk.SearchClient",
    )
    assert etree.tag == "document"

    title = etree.find("./section/title")
    assert title.text == "globus_sdk.SearchClient"

    dropdowns = etree.findall("./section/container[@design_component='dropdown']")
    # we don't care about exactly what methods are found and produced as dropdowns
    # we just want to make sure there are "some"
    assert len(dropdowns) > 1

    # grab the first dropdown and inspect it
    first_dropdown = dropdowns[0]
    # find the title, make sure it matches a real method
    fixture_title = first_dropdown.find("./rubric/literal")
    assert fixture_title is not None
    first_method_name = fixture_title.text
    assert hasattr(globus_sdk.SearchClient, first_method_name)
    first_method = getattr(globus_sdk.SearchClient, first_method_name)
    assert isinstance(first_method, types.FunctionType)

    # for each dropdown, there should be a content area and it should contain valid JSON
    for dropdown in dropdowns:
        fixture_title = dropdown.find("./rubric/literal").text
        example_block = dropdown.find("./literal_block")
        assert example_block is not None
        assert example_block.get("language") == "json"
        content = example_block.text
        try:
            json.loads(content)
        except json.JSONDecodeError:
            pytest.fail(
                f"{fixture_title} in SearchClient fixture docs didn't have JSON content"
            )