예제 #1
0
파일: test_misc.py 프로젝트: yleng/pybnb
    def test_get_keyword_docs(self):
        if not yaml_available:
            pytest.skip("yaml is not available")
        import pybnb.solver
        data = get_keyword_docs(pybnb.solver.Solver.solve.__doc__)
        kwds = get_default_args(pybnb.solver.Solver.solve)
        assert len(data) > 1
        for key in data:
            if 'default' in data[key]:
                assert data[key]['default'] == kwds[key]
            assert "choices" not in data[key]

        def f():
            """Something

            Parameters
            ----------
            junk1 : {"a", "b", 1}
                Junk1 description.
            junk2 : {"c", "d"}, optional
                Junk2 description more than one
                line. (default: "c")
            junk3 : int
                Junk3 description.
            """

        data = get_keyword_docs(f.__doc__)
        assert data == \
            {'junk1': {'choices': ['a', 'b', 1],
                       'doc': 'Junk1 description.'},
             'junk2': {'choices': ['c', 'd'],
                       'default': 'c',
                       'doc': 'Junk2 description more than one line.'},
             'junk3': {'doc': 'Junk3 description.'}}
예제 #2
0
파일: test_misc.py 프로젝트: yleng/pybnb
    def test_get_default_args(self):
        def f(a):  #pragma:nocover
            pass

        assert get_default_args(f) == {}

        def f(a, b):  #pragma:nocover
            pass

        assert get_default_args(f) == {}

        def f(*args):  #pragma:nocover
            pass

        assert get_default_args(f) == {}

        def f(**kwds):  #pragma:nocover
            pass

        assert get_default_args(f) == {}

        def f(*args, **kwds):  #pragma:nocover
            pass

        assert get_default_args(f) == {}

        def f(a, b=1):  #pragma:nocover
            pass

        assert get_default_args(f) == {'b': 1}

        def f(a=1):  #pragma:nocover
            pass

        assert get_default_args(f) == {'a': 1}

        def f(a=(1, )):  #pragma:nocover
            pass

        assert get_default_args(f) == {'a': (1, )}
예제 #3
0
    def test_get_default_args(self):
        def f(a):  #pragma:nocover
            pass

        assert get_default_args(f) == {}

        def f(a, b):  #pragma:nocover
            pass

        assert get_default_args(f) == {}

        def f(*args):  #pragma:nocover
            pass

        assert get_default_args(f) == {}

        def f(**kwds):  #pragma:nocover
            pass

        assert get_default_args(f) == {}

        def f(*args, **kwds):  #pragma:nocover
            pass

        assert get_default_args(f) == {}

        def f(a, b=1):  #pragma:nocover
            pass

        assert get_default_args(f) == {'b': 1}

        def f(a=[]):
            a.append(1)

        assert get_default_args(f) == {'a': []}
        f()
        assert get_default_args(f) == {'a': [1]}
예제 #4
0
    def test_get_keyword_docs(self):
        if not yaml_available:
            pytest.skip("yaml is not available")
        import pybnb.solver

        data = get_keyword_docs(pybnb.solver.Solver.solve.__doc__)
        kwds = get_default_args(pybnb.solver.Solver.solve)
        assert len(data) > 1
        for key in data:
            if "default" in data[key]:
                assert data[key]["default"] == kwds[key]
            assert "choices" not in data[key]

        def f():
            """Something

            Parameters
            ----------
            junk1 : {"a", "b", 1}
                Junk1 description.
            junk2 : {"c", "d"}, optional
                Junk2 description more than one
                line. (default: "c")
            junk3 : int
                Junk3 description.
            """

        data = get_keyword_docs(f.__doc__)
        assert data == {
            "junk1": {"choices": ["a", "b", 1], "doc": "Junk1 description."},
            "junk2": {
                "choices": ["c", "d"],
                "default": "c",
                "doc": "Junk2 description more than one line.",
            },
            "junk3": {"doc": "Junk3 description."},
        }