Esempio n. 1
0
def depth_two(inp, expected, args):
    results = []
    depth_2_template = '{}.{}({}) = {} ---> {}.{}({}) = {}'
    for x in remember(inp, PassAnything(), args):
        newinp = copy.copy(inp)
        try:
            res = call_self_by_arity(x['callable'], newinp, x['arity'])
            arg1 = args if x['arity'] == '1' else ''
        except NoValidResultError:
            continue
        try:
            n = remember(res, expected, args)
        # catching Python 2.x:
        # TypeError: object.__new__(listiterator) is not safe, use listiterator.__new__()
        except TypeError:
            continue
        oldinp = copy.copy(newinp)
        for r in n:
            if r['arity'] == '1':
                arg2 = args
            elif r['arity'] == 'starred':
                arg2 = '*' + str(args)
            else:
                arg2 = ''
            results.append(
                depth_2_template.format(
                    inp, x['callable'], arg1, res, res, r['callable'], arg2, expected
                )
            )
    return results
Esempio n. 2
0
def test_class_instance_methods():
    """
    Testing whether a class' instance method can be used.
    Testing whether a class' class method can be used.
    """
    inp = TestClassInstanceMethods()
    expected = 42
    assert result_contains_callable(remember(inp, expected), 'some_instance_method')
    assert result_contains_callable(remember(inp, expected), 'class_method')
Esempio n. 3
0
def test_class_instance_methods():
    """
    Testing whether a class' instance method can be used.
    Testing whether a class' class method can be used.
    """
    inp = TestClassInstanceMethods()
    expected = 42
    assert result_contains_callable(remember(inp, expected),
                                    'some_instance_method')
    assert result_contains_callable(remember(inp, expected), 'class_method')
Esempio n. 4
0
def test_global_arity0():
    """ Test whether the above current scope function can be used to solve this case """
    inp = 1
    expected = 42
    assert result_contains_callable(
        remember(inp, expected, globals_dict=TEST_CURRENT_GLOBALS),
        'global_arity_0')
Esempio n. 5
0
def test_general_set_difference():
    """ Testing whether set difference is found for overlapping sets. """
    inp = set([5, 6, 7, 8])
    args = set([5, 8])
    expected = set([6, 7])
    assert result_contains_callable(remember(inp, expected, args),
                                    'difference')
Esempio n. 6
0
def test_general_set_intersection2():
    """ Testing whether set intersection is found for overlapping sets. """
    inp = set([2, 3])
    args = [3, 5]
    expected = set([3])
    assert result_contains_callable(remember(inp, expected, args),
                                    'intersection')
Esempio n. 7
0
def test_general_set_intersection():
    """ Testing whether set difference is not found for not overlapping sets. """
    inp = set([2, 3])
    args = [4]
    expected = set()
    assert result_contains_callable(remember(inp, expected, args),
                                    'intersection')
Esempio n. 8
0
def test_module_itertools():
    """ Testing the module scope. """
    import itertools
    inp = [1, 2, 3]
    args = 2
    expected = [(1, 2), (1, 3), (2, 3)]
    assert result_contains_callable(remember(inp, expected, args, module_namespace=itertools),
                                    'itertools.combinations')
Esempio n. 9
0
def test_module_itertools():
    """ Testing the module scope. """
    import itertools
    inp = [1, 2, 3]
    args = 2
    expected = [(1, 2), (1, 3), (2, 3)]
    assert result_contains_callable(
        remember(inp, expected, args, module_namespace=itertools),
        'itertools.combinations')
Esempio n. 10
0
def test_builtins_str():
    """ Testing whether builtins can be used to solve. """
    inp = 1
    expected = '1'
    assert result_contains_callable(remember(inp, expected, builtins_namespace=True), 'str')
Esempio n. 11
0
def test_builtins_float():
    """ Testing whether builtins can be used to solve. """
    inp = 10
    expected = 10.0
    assert result_contains_callable(remember(inp, expected, builtins_namespace=True), 'float')
Esempio n. 12
0
def test_math_ceil():
    """ Test whether the above current scope function can be used to solve this case """
    inp = 12.1
    expected = 13
    assert result_contains_callable(
        remember(inp, expected, globals_dict=globals()), 'ceil')
Esempio n. 13
0
def test_builtins_float():
    """ Testing whether builtins can be used to solve. """
    inp = 10
    expected = 10.0
    assert result_contains_callable(
        remember(inp, expected, builtins_namespace=True), 'float')
Esempio n. 14
0
def test_general_set_difference():
    """ Testing whether set difference is found for overlapping sets. """
    inp = set([5, 6, 7, 8])
    args = set([5, 8])
    expected = set([6, 7])
    assert result_contains_callable(remember(inp, expected, args), 'difference')
Esempio n. 15
0
def test_general_set_intersection2():
    """ Testing whether set intersection is found for overlapping sets. """
    inp = set([2, 3])
    args = [3, 5]
    expected = set([3])
    assert result_contains_callable(remember(inp, expected, args), 'intersection')
Esempio n. 16
0
def test_general_set_union():
    """ Testing whether set union is found for combining sets. """
    inp = set([2, 3])
    args = [3, 4]
    expected = set([2, 3, 4])
    assert result_contains_callable(remember(inp, expected, args), 'union')
Esempio n. 17
0
def test_general_set_pop_arity1():
    """ Testing set.pop (which takes no arguments) and return 2. """
    inp = set([2, 3, 4])
    expected = 2
    assert result_contains_callable(remember(inp, expected), 'pop')
Esempio n. 18
0
def test_general_set_union():
    """ Testing whether set union is found for combining sets. """
    inp = set([2, 3])
    args = [3, 4]
    expected = set([2, 3, 4])
    assert result_contains_callable(remember(inp, expected, args), 'union')
Esempio n. 19
0
def test_pass_anything():
    """ Testing whether PassAnything class works when expecting no value, just no errors. """
    inp = 42
    expected = PassAnything()
    assert result_contains_callable(remember(inp, expected), '__add__')
Esempio n. 20
0
def test_global_arity1():
    """ Test whether the above current scope function can be used to solve this case """
    inp = 1
    expected = 42
    assert result_contains_callable(
        remember(inp, expected, globals_dict=globals()), 'global_arity_1')
Esempio n. 21
0
def test_builtins_str():
    """ Testing whether builtins can be used to solve. """
    inp = 1
    expected = '1'
    assert result_contains_callable(
        remember(inp, expected, builtins_namespace=True), 'str')
Esempio n. 22
0
def test_pass_anything():
    """ Testing whether PassAnything class works when expecting no value, just no errors. """
    inp = 42
    expected = PassAnything()
    assert result_contains_callable(remember(inp, expected), '__add__')
Esempio n. 23
0
def test_general_integer_add():
    """ Testing whether integer add is found to solve 42+42=84. """
    inp = 42
    args = 42
    expected = 84
    assert result_contains_callable(remember(inp, expected, args), 'add')
Esempio n. 24
0
def test_general_set_intersection():
    """ Testing whether set difference is not found for not overlapping sets. """
    inp = set([2, 3])
    args = [4]
    expected = set()
    assert result_contains_callable(remember(inp, expected, args), 'intersection')
Esempio n. 25
0
def test_global_arity0():
    """ Test whether the above current scope function can be used to solve this case """
    inp = 1
    expected = 42
    assert result_contains_callable(remember(inp, expected, globals_dict=TEST_CURRENT_GLOBALS),
                                    'global_arity_0')
Esempio n. 26
0
def test_general_set_pop_arity1():
    """ Testing set.pop (which takes no arguments) and return 2. """
    inp = set([2, 3, 4])
    expected = 2
    assert result_contains_callable(remember(inp, expected), 'pop')
Esempio n. 27
0
def test_global_arity1():
    """ Test whether the above current scope function can be used to solve this case """
    inp = 1
    expected = 42
    assert result_contains_callable(
        remember(inp, expected, globals_dict=globals()), 'global_arity_1')
Esempio n. 28
0
def test_general_integer_add():
    """ Testing whether integer add is found to solve 42+42=84. """
    inp = 42
    args = 42
    expected = 84
    assert result_contains_callable(remember(inp, expected, args), 'add')
Esempio n. 29
0
def test_math_ceil():
    """ Test whether the above current scope function can be used to solve this case """
    inp = 12.1
    expected = 13
    assert result_contains_callable(
        remember(inp, expected, globals_dict=globals()), 'ceil')