Exemple #1
0
    def test_filter_class(self):
        class CTG(Grid):
            Column('First Name', Person.firstname, TextFilter)
            Column('Last Name', Person.lastname, TextFilter)

        g = CTG()
        g.set_filter('firstname', 'eq', 'foo')
        assert_in_query(g, "WHERE upper(persons.firstname) = upper('foo')")

        with mock.patch('logging.Logger.debug') as m_debug:
            g.records
            g.set_filter('lastname', 'eq', 'bar')
            g.records
            expected = [
                r'^<Grid "CTG">$',
                r'^firstname: class=TextFilter, op=eq, value1=foo, value2=None$',
                r'^No sorts$',
                r'^Page 1; 50 per page$',
                r'^Data query ran in \d+\.?\d* seconds$',
                r'^<Grid "CTG">$',
                r'^firstname: class=TextFilter, op=eq, value1=foo, value2=None;'
                r'lastname: class=TextFilter, op=eq, value1=bar, value2=None$',
                r'^No sorts$',
                r'^Page 1; 50 per page$',
                r'^Data query ran in \d+\.?\d* seconds$',
            ]
            eq_(len(expected), len(m_debug.call_args_list))
            for idx, call in enumerate(m_debug.call_args_list):
                assert_regex(call[0][0], expected[idx])
def test_info():
    "Check that Inspector.info fills out various fields as expected."
    i = inspector.info(Call, oname='Call')
    nt.assert_equal(i['type_name'], 'type')
    expted_class = str(type(type))  # <class 'type'> (Python 3) or <type 'type'>
    nt.assert_equal(i['base_class'], expted_class)
    nt.assert_regex(i['string_form'], "<class 'IPython.core.tests.test_oinspect.Call'( at 0x[0-9a-f]{1,9})?>")
    fname = __file__
    if fname.endswith(".pyc"):
        fname = fname[:-1]
    # case-insensitive comparison needed on some filesystems
    # e.g. Windows:
    nt.assert_equal(i['file'].lower(), compress_user(fname).lower())
    nt.assert_equal(i['definition'], None)
    nt.assert_equal(i['docstring'], Call.__doc__)
    nt.assert_equal(i['source'], None)
    nt.assert_true(i['isclass'])
    nt.assert_equal(i['init_definition'], "Call(x, y=1)")
    nt.assert_equal(i['init_docstring'], Call.__init__.__doc__)

    i = inspector.info(Call, detail_level=1)
    nt.assert_not_equal(i['source'], None)
    nt.assert_equal(i['docstring'], None)

    c = Call(1)
    c.__doc__ = "Modified instance docstring"
    i = inspector.info(c)
    nt.assert_equal(i['type_name'], 'Call')
    nt.assert_equal(i['docstring'], "Modified instance docstring")
    nt.assert_equal(i['class_docstring'], Call.__doc__)
    nt.assert_equal(i['init_docstring'], Call.__init__.__doc__)
    nt.assert_equal(i['call_docstring'], Call.__call__.__doc__)
def test_info():
    "Check that Inspector.info fills out various fields as expected."
    i = inspector.info(Call, oname='Call')
    nt.assert_equal(i['type_name'], 'type')
    expted_class = str(type(type))  # <class 'type'> (Python 3) or <type 'type'>
    nt.assert_equal(i['base_class'], expted_class)
    nt.assert_regex(i['string_form'], "<class 'IPython.core.tests.test_oinspect.Call'( at 0x[0-9a-f]{1,9})?>")
    fname = __file__
    if fname.endswith(".pyc"):
        fname = fname[:-1]
    # case-insensitive comparison needed on some filesystems
    # e.g. Windows:
    nt.assert_equal(i['file'].lower(), compress_user(fname).lower())
    nt.assert_equal(i['definition'], None)
    nt.assert_equal(i['docstring'], Call.__doc__)
    nt.assert_equal(i['source'], None)
    nt.assert_true(i['isclass'])
    nt.assert_equal(i['init_definition'], "Call(x, y=1)")
    nt.assert_equal(i['init_docstring'], Call.__init__.__doc__)

    i = inspector.info(Call, detail_level=1)
    nt.assert_not_equal(i['source'], None)
    nt.assert_equal(i['docstring'], None)

    c = Call(1)
    c.__doc__ = "Modified instance docstring"
    i = inspector.info(c)
    nt.assert_equal(i['type_name'], 'Call')
    nt.assert_equal(i['docstring'], "Modified instance docstring")
    nt.assert_equal(i['class_docstring'], Call.__doc__)
    nt.assert_equal(i['init_docstring'], Call.__init__.__doc__)
    nt.assert_equal(i['call_docstring'], Call.__call__.__doc__)
Exemple #4
0
 def check_value_string(self, term_string):
     if self.is_pointer:
         return
     variable_regex = '[A-Z_][A-Za-z0-9_]*'
     prolog_string_regex = (
         '^' +
         re.escape(self.prolog_string).replace('\%v', variable_regex) + '$')
     assert_regex(term_string, prolog_string_regex)
def test_path_regex():
    for path in (
            '/x',
            '/x/',
            '/x/foo',
            '/x/foo.ipynb',
            '/x/foo/bar',
            '/x/foo/bar.txt',
    ):
        assert_regex(path, path_pat)
Exemple #6
0
 def test_record_count(self, m_debug):
     g = self.TG()
     eq_(g.record_count, 5)
     expected = [
         r'^<Grid "TG">$',
         r'^No filters$',
         r'^Count query ran in \d+\.?\d* seconds$',
     ]
     eq_(len(expected), len(m_debug.call_args_list))
     for idx, call in enumerate(m_debug.call_args_list):
         assert_regex(call[0][0], expected[idx])
Exemple #7
0
 def assert_(self, stdout='', stderr='', rc=0):
     if stderr is None:
         pass
     elif isinstance(stderr, re_type):
         assert_regex(self.stderr, stderr)
     else:
         assert_multi_line_equal(self.stderr, stderr)
     if rc is not None:
         assert_equal(_ipc_rc(self.rc), _ipc_rc(rc))
     if stdout is None:
         pass
     elif isinstance(stdout, re_type):
         assert_regex(self.stdout, stdout)
     else:
         assert_multi_line_equal(self.stdout, stdout)
Exemple #8
0
 def test_external_refs(self):
     """If a bundle contains absolute paths outside of the
     media directory, to generate a url they are copied in.
     """
     try:
         from nose.tools import assert_regex
     except ImportError:
         raise SkipTest("Assertion method only present in 2.7+")
     self.env.debug = True
     with TempDirHelper() as h:
         h.create_files(['foo.css'])
         bundle = self.mkbundle(h.path('foo.css'))
         urls = bundle.urls()
         assert len(urls) == 1
         assert_regex(urls[0], r'.*/webassets-external/[\da-z]*_foo.css')
Exemple #9
0
def test_info():
    "Check that Inspector.info fills out various fields as expected."
    i = inspector.info(Call, oname='Call')
    nt.assert_equal(i['type_name'], 'type')
    expted_class = str(
        type(type))  # <class 'type'> (Python 3) or <type 'type'>
    nt.assert_equal(i['base_class'], expted_class)
    if sys.version_info > (3, ):
        nt.assert_regex(
            i['string_form'],
            "<class 'IPython.core.tests.test_oinspect.Call'( at 0x[0-9a-f]{1,9})?>"
        )
    fname = __file__
    if fname.endswith(".pyc"):
        fname = fname[:-1]
    # case-insensitive comparison needed on some filesystems
    # e.g. Windows:
    nt.assert_equal(i['file'].lower(), compress_user(fname).lower())
    nt.assert_equal(i['definition'], None)
    nt.assert_equal(i['docstring'], Call.__doc__)
    nt.assert_equal(i['source'], None)
    nt.assert_true(i['isclass'])
    _self_py2 = '' if py3compat.PY3 else 'self, '
    nt.assert_equal(i['init_definition'], "Call(%sx, y=1)\n" % _self_py2)
    nt.assert_equal(i['init_docstring'], Call.__init__.__doc__)

    i = inspector.info(Call, detail_level=1)
    nt.assert_not_equal(i['source'], None)
    nt.assert_equal(i['docstring'], None)

    c = Call(1)
    c.__doc__ = "Modified instance docstring"
    i = inspector.info(c)
    nt.assert_equal(i['type_name'], 'Call')
    nt.assert_equal(i['docstring'], "Modified instance docstring")
    nt.assert_equal(i['class_docstring'], Call.__doc__)
    nt.assert_equal(i['init_docstring'], Call.__init__.__doc__)
    nt.assert_equal(i['call_docstring'], Call.__call__.__doc__)

    # Test old-style classes, which for example may not have an __init__ method.
    if not py3compat.PY3:
        i = inspector.info(OldStyle)
        nt.assert_equal(i['type_name'], 'classobj')

        i = inspector.info(OldStyle())
        nt.assert_equal(i['type_name'], 'instance')
        nt.assert_equal(i['docstring'], OldStyle.__doc__)
Exemple #10
0
def test_info():
    "Check that Inspector.info fills out various fields as expected."
    i = inspector.info(Call, oname='Call')
    nt.assert_equal(i['type_name'], 'type')
    expted_class = str(type(type))  # <class 'type'> (Python 3) or <type 'type'>
    nt.assert_equal(i['base_class'], expted_class)
    if sys.version_info > (3,):
        nt.assert_regex(i['string_form'], "<class 'IPython.core.tests.test_oinspect.Call'( at 0x[0-9a-f]{1,9})?>")
    fname = __file__
    if fname.endswith(".pyc"):
        fname = fname[:-1]
    # case-insensitive comparison needed on some filesystems
    # e.g. Windows:
    nt.assert_equal(i['file'].lower(), compress_user(fname).lower())
    nt.assert_equal(i['definition'], None)
    nt.assert_equal(i['docstring'], Call.__doc__)
    nt.assert_equal(i['source'], None)
    nt.assert_true(i['isclass'])
    _self_py2 = '' if py3compat.PY3 else 'self, '
    nt.assert_equal(i['init_definition'], "Call(%sx, y=1)" % _self_py2)
    nt.assert_equal(i['init_docstring'], Call.__init__.__doc__)

    i = inspector.info(Call, detail_level=1)
    nt.assert_not_equal(i['source'], None)
    nt.assert_equal(i['docstring'], None)

    c = Call(1)
    c.__doc__ = "Modified instance docstring"
    i = inspector.info(c)
    nt.assert_equal(i['type_name'], 'Call')
    nt.assert_equal(i['docstring'], "Modified instance docstring")
    nt.assert_equal(i['class_docstring'], Call.__doc__)
    nt.assert_equal(i['init_docstring'], Call.__init__.__doc__)
    nt.assert_equal(i['call_docstring'], Call.__call__.__doc__)

    # Test old-style classes, which for example may not have an __init__ method.
    if not py3compat.PY3:
        i = inspector.info(OldStyle)
        nt.assert_equal(i['type_name'], 'classobj')

        i = inspector.info(OldStyle())
        nt.assert_equal(i['type_name'], 'instance')
        nt.assert_equal(i['docstring'], OldStyle.__doc__)
Exemple #11
0
    def test_subtotal_sum_by_default(self, m_debug):
        class CTG(Grid):
            Column('Sum Total',
                   Person.numericcol.label('something'),
                   has_subtotal=True)

        Person.testing_create(numericcol=5)
        Person.testing_create(numericcol=10)
        g = CTG()
        totals = g.grand_totals
        assert totals.something == 15
        expected = [
            r'^<Grid "CTG">$',
            r'^No filters$',
            r'^Totals query ran in \d+\.?\d* seconds$',
        ]
        eq_(len(expected), len(m_debug.call_args_list))
        for idx, call in enumerate(m_debug.call_args_list):
            assert_regex(call[0][0], expected[idx])
Exemple #12
0
    def test_order_by(self):
        class CTG(Grid):
            Column('First Name', Person.firstname)

        g = CTG()
        g.set_sort('-firstname')
        assert_in_query(g, 'ORDER BY persons.firstname')
        with mock.patch('logging.Logger.debug') as m_debug:
            g.records
            expected = [
                r'^<Grid "CTG">$',
                r'^No filters$',
                r'^firstname$',
                r'^Page 1; 50 per page$',
                r'^Data query ran in \d+\.?\d* seconds$',
            ]
            eq_(len(expected), len(m_debug.call_args_list))
            for idx, call in enumerate(m_debug.call_args_list):
                assert_regex(call[0][0], expected[idx])
Exemple #13
0
def test_cursor_values():
    ax = plt.axes(projection=ccrs.NorthPolarStereo())
    x, y = np.array([-969100.]), np.array([-4457000.])
    r = ax.format_coord(x, y)
    assert_equal(r.encode('ascii', 'ignore'),
                 six.b('-9.691e+05, -4.457e+06 (50.716617N, 12.267069W)'))

    ax = plt.axes(projection=ccrs.PlateCarree())
    x, y = np.array([-181.5]), np.array([50.])
    r = ax.format_coord(x, y)
    assert_equal(r.encode('ascii', 'ignore'),
                 six.b('-181.5, 50 (50.000000N, 178.500000E)'))

    ax = plt.axes(projection=ccrs.Robinson())
    x, y = np.array([16060595.2]), np.array([2363093.4])
    r = ax.format_coord(x, y)
    assert_regex(r.encode('ascii', 'ignore'),
                 six.b('1.606e\\+07, 2.363e\\+06 '
                       '\\(22.09[0-9]{4}N, 173.70[0-9]{4}E\\)'))

    plt.close()
Exemple #14
0
    def test_base_query(self):
        class CTG(Grid):
            Column('First Name', Person.firstname)

        g = CTG()
        query = g.build_query()
        assert_not_in_query(query, 'WHERE')
        assert_not_in_query(query, 'ORDER BY')
        with mock.patch('logging.Logger.debug') as m_debug:
            rs = g.records
            assert len(rs) > 0, rs
            expected = [
                r'^<Grid "CTG">$',
                r'^No filters$',
                r'^No sorts$',
                r'^Page 1; 50 per page$',
                r'^Data query ran in \d+\.?\d* seconds$',
            ]
            eq_(len(expected), len(m_debug.call_args_list))
            for idx, call in enumerate(m_debug.call_args_list):
                assert_regex(call[0][0], expected[idx])
def test_cursor_values():
    ax = plt.axes(projection=ccrs.NorthPolarStereo())
    x, y = np.array([-969100.]), np.array([-4457000.])
    r = ax.format_coord(x, y)
    assert_equal(r.encode('ascii', 'ignore'),
                 six.b('-9.691e+05, -4.457e+06 (50.716617N, 12.267069W)'))

    ax = plt.axes(projection=ccrs.PlateCarree())
    x, y = np.array([-181.5]), np.array([50.])
    r = ax.format_coord(x, y)
    assert_equal(r.encode('ascii', 'ignore'),
                 six.b('-181.5, 50 (50.000000N, 178.500000E)'))

    ax = plt.axes(projection=ccrs.Robinson())
    x, y = np.array([16060595.2]), np.array([2363093.4])
    r = ax.format_coord(x, y)
    assert_regex(r.encode('ascii', 'ignore'),
                 six.b('1.606e\\+07, 2.363e\\+06 '
                       '\\(22.09[0-9]{4}N, 173.70[0-9]{4}E\\)'))

    plt.close()
Exemple #16
0
def test_info():
    "Check that Inspector.info fills out various fields as expected."
    i = inspector.info(Call, oname="Call")
    assert i["type_name"] == "type"
    expted_class = str(
        type(type))  # <class 'type'> (Python 3) or <type 'type'>
    assert i["base_class"] == expted_class
    nt.assert_regex(
        i["string_form"],
        "<class 'IPython.core.tests.test_oinspect.Call'( at 0x[0-9a-f]{1,9})?>",
    )
    fname = __file__
    if fname.endswith(".pyc"):
        fname = fname[:-1]
    # case-insensitive comparison needed on some filesystems
    # e.g. Windows:
    assert i["file"].lower() == compress_user(fname).lower()
    assert i["definition"] == None
    assert i["docstring"] == Call.__doc__
    assert i["source"] == None
    nt.assert_true(i["isclass"])
    assert i["init_definition"] == "Call(x, y=1)"
    assert i["init_docstring"] == Call.__init__.__doc__

    i = inspector.info(Call, detail_level=1)
    nt.assert_not_equal(i["source"], None)
    assert i["docstring"] == None

    c = Call(1)
    c.__doc__ = "Modified instance docstring"
    i = inspector.info(c)
    assert i["type_name"] == "Call"
    assert i["docstring"] == "Modified instance docstring"
    assert i["class_docstring"] == Call.__doc__
    assert i["init_docstring"] == Call.__init__.__doc__
    assert i["call_docstring"] == Call.__call__.__doc__
Exemple #17
0
 def test__repr__(self):
     assert_regex(repr(self.term),
                  "Term\(handle=\d*, type={!s}, value={!s}\)".format(
                      re.escape(repr(self.type_)),
                      re.escape(repr(str(self.term)))))
def test_docstring_addition():
    @unpack_labeled_data()
    def funcy(ax, *args, **kwargs):
        """Funcy does nothing"""
        pass

    assert_regex(funcy.__doc__,
                 r".*All positional and all keyword arguments\.")
    assert_not_regex(funcy.__doc__, r".*All positional arguments\.")
    assert_not_regex(funcy.__doc__,
                     r".*All arguments with the following names: .*")

    @unpack_labeled_data(replace_all_args=True, replace_names=[])
    def funcy(ax, x, y, z, bar=None):
        """Funcy does nothing"""
        pass

    assert_regex(funcy.__doc__, r".*All positional arguments\.")
    assert_not_regex(funcy.__doc__,
                     r".*All positional and all keyword arguments\.")
    assert_not_regex(funcy.__doc__,
                     r".*All arguments with the following names: .*")

    @unpack_labeled_data(replace_all_args=True, replace_names=["bar"])
    def funcy(ax, x, y, z, bar=None):
        """Funcy does nothing"""
        pass

    assert_regex(funcy.__doc__, r".*All positional arguments\.")
    assert_regex(funcy.__doc__,
                 r".*All arguments with the following names: 'bar'\.")
    assert_not_regex(funcy.__doc__,
                     r".*All positional and all keyword arguments\.")

    @unpack_labeled_data(replace_names=["x", "bar"])
    def funcy(ax, x, y, z, bar=None):
        """Funcy does nothing"""
        pass

    # lists can print in any order, so test for both x,bar and bar,x
    assert_regex(funcy.__doc__,
                 r".*All arguments with the following names: '.*', '.*'\.")
    assert_regex(funcy.__doc__, r".*'x'.*")
    assert_regex(funcy.__doc__, r".*'bar'.*")
    assert_not_regex(funcy.__doc__,
                     r".*All positional and all keyword arguments\.")
    assert_not_regex(funcy.__doc__, r".*All positional arguments\.")
def test_docstring_addition():
    @unpack_labeled_data()
    def funcy(ax, *args, **kwargs):
        """Funcy does nothing"""
        pass

    assert_regex(funcy.__doc__,
                          r".*All positional and all keyword arguments\.")
    assert_not_regex(funcy.__doc__, r".*All positional arguments\.")
    assert_not_regex(funcy.__doc__,
                              r".*All arguments with the following names: .*")

    @unpack_labeled_data(replace_all_args=True, replace_names=[])
    def funcy(ax, x, y, z, bar=None):
        """Funcy does nothing"""
        pass

    assert_regex(funcy.__doc__, r".*All positional arguments\.")
    assert_not_regex(funcy.__doc__,
                              r".*All positional and all keyword arguments\.")
    assert_not_regex(funcy.__doc__,
                              r".*All arguments with the following names: .*")

    @unpack_labeled_data(replace_all_args=True, replace_names=["bar"])
    def funcy(ax, x, y, z, bar=None):
        """Funcy does nothing"""
        pass

    assert_regex(funcy.__doc__, r".*All positional arguments\.")
    assert_regex(funcy.__doc__,
                          r".*All arguments with the following names: 'bar'\.")
    assert_not_regex(funcy.__doc__,
                              r".*All positional and all keyword arguments\.")

    @unpack_labeled_data(replace_names=["x", "bar"])
    def funcy(ax, x, y, z, bar=None):
        """Funcy does nothing"""
        pass

    # lists can print in any order, so test for both x,bar and bar,x
    assert_regex(funcy.__doc__,
                    r".*All arguments with the following names: '.*', '.*'\.")
    assert_regex(funcy.__doc__, r".*'x'.*")
    assert_regex(funcy.__doc__, r".*'bar'.*")
    assert_not_regex(funcy.__doc__,
                              r".*All positional and all keyword arguments\.")
    assert_not_regex(funcy.__doc__, r".*All positional arguments\.")
Exemple #20
0
def assert_uuid_urn(uuid):
    return assert_regex(
        uuid,
        _uuid_regex,
    )
Exemple #21
0
 async def test_data_after_done(self) -> None:
     await self.client.request('capture-init', self.cbid)
     await self.client.request('capture-done', self.cbid)
     with assert_logs('katsdpdatawriter.flag_writer', 'WARNING') as cm:
         await self.send_heap(self.tx[0], self.ig.get_heap())
     assert_regex(cm.output[0], 'outside of init/done')