예제 #1
0
        def mara(cond, cond2):
            assert_is_value(cond, UNRESOLVED_VALUE)
            assert_is_instance(cond, int)
            assert_is_value(cond, TypedValue(int))

            assert_is_instance(cond2, (int, str))
            assert_is_value(cond2, MultiValuedValue([TypedValue(int), TypedValue(str)]))
예제 #2
0
def test_intenum():
    assert_is_instance(Python.two, int)
    assert_eq('Python.two', repr(Python.two))
    assert_eq('2', json.dumps(Python.two))
    assert_in(Python.two, Python)
    assert_in(2, Python)
    assert_not_in(4, Python)
예제 #3
0
 def __init__(self, scope_type, variables, parent_scope, scope_node=None):
     assert_is_instance(scope_type, ScopeType)
     self.scope_type = scope_type
     assert_is_instance(variables, dict)
     self.variables = variables
     if parent_scope is not None:
         self.parent_scope = parent_scope.scope_used_as_parent()
     else:
         self.parent_scope = None
     self.scope_node = scope_node
예제 #4
0
def test_get_async_fn():
    assert_eq(async_fn.asynq, get_async_fn(async_fn))
    assert_eq(lazy_fn, get_async_fn(lazy_fn))
    assert_is(None, get_async_fn(sync_fn))

    wrapper = get_async_fn(sync_fn, wrap_if_none=True)
    assert is_pure_async_fn(wrapper)
    result = wrapper()
    assert_is_instance(result, ConstFuture)
    assert_eq("sync_fn", result.value())
예제 #5
0
def test_async_proxy():
    assert_eq('sync_proxied_fn', sync_proxied_fn())
    assert_eq('sync_proxied_fn', async_proxied_fn())

    result = async_proxied_fn.asynq()
    assert_is_instance(result, ConstFuture)
    assert_eq('async_proxied_fn', result.value())

    with AssertRaises(AssertionError):
        @async_proxy(pure=True, sync_fn=sync_proxied_fn)
        def this_doesnt_make_sense():
            pass
예제 #6
0
def test_values():
    gen = generator_with_more_yields()
    for i in range(3):
        task = next(gen)
        assert_is_instance(task, AsyncTask)
        assert_eq(i, task.value())

    task = next(gen)
    assert_is_instance(task, AsyncTask)
    assert_is(END_OF_GENERATOR, task.value())

    with AssertRaises(StopIteration):
        next(gen)
예제 #7
0
def test_marker_object():
    assert_eq("text", six.text_type(qcore.MarkerObject("text")))
    assert_is_instance(six.text_type(qcore.MarkerObject("text")),
                       six.text_type)

    # bytes should work in py2 but not py3
    if six.PY2:
        assert_eq(u"bytes", six.text_type(qcore.MarkerObject(b"bytes")))
        assert_eq(b"bytes", six.binary_type(qcore.MarkerObject(b"bytes")))
    else:
        with AssertRaises(TypeError):
            qcore.MarkerObject(b"bytes")

    # MarkerObjects should be unique
    assert_ne(qcore.MarkerObject("name"), qcore.MarkerObject("name"))
예제 #8
0
def test_marker_object():
    assert_eq('text', six.text_type(qcore.MarkerObject('text')))
    assert_is_instance(six.text_type(qcore.MarkerObject('text')),
                       six.text_type)

    # bytes should work in py2 but not py3
    if six.PY2:
        assert_eq(u'bytes', six.text_type(qcore.MarkerObject(b'bytes')))
        assert_eq(b'bytes', six.binary_type(qcore.MarkerObject(b'bytes')))
    else:
        with AssertRaises(TypeError):
            qcore.MarkerObject(b'bytes')

    # MarkerObjects should be unique
    assert_ne(qcore.MarkerObject('name'), qcore.MarkerObject('name'))
예제 #9
0
def test_event_hub():
    h = qcore.EventHub()

    assert_eq(0, len(h))
    assert_eq('EventHub({})', repr(h))

    with AssertRaises(AttributeError):
        h.doesnt_start_with_on

    h_e = h.on_e
    assert_is_instance(h_e, qcore.EventHook)
    assert_eq(1, len(h))
    assert_is(h_e, h['e'])
    assert_eq("EventHub({'e': %r})" % h_e, repr(h))
    assert_is(h, h.safe_trigger('e'))
    assert_is(h, h.trigger('e'))

    h_e.subscribe(lambda: 0)

    assert_in('e', h)
    assert_not_in('f', h)

    h['f'] = None
    assert_is(None, h['f'])
    assert_in('f', h)
    assert_eq(2, len(h))

    del h['f']
    assert_not_in('f', h)
    assert_eq(1, len(h))

    for k, v in h:
        assert_eq('e', k)
        assert_is(h_e, v)

    def bad_fn(*args):
        raise NotImplementedError()

    m = mock.MagicMock()
    h.on_test.subscribe(bad_fn)
    with AssertRaises(NotImplementedError):
        h.on('test', m).safe_trigger('test', 1)
    m.assert_called_once_with(1)
    m.reset_mock()

    h.off('test', bad_fn).trigger('test', 2, 3)
    m.assert_called_once_with(2, 3)
예제 #10
0
def test_long_enum():
    assert_is_instance(LongEnum.x, LongEnum)
예제 #11
0
def assert_cannot_assign(left: Value, right: Value) -> None:
    tv_map = left.can_assign(right, CTX)
    assert_is_instance(tv_map, CanAssignError)
    print(tv_map.display())