Пример #1
0
    def test_empty_stripes(self):
        r = []
        s = self.schema1
        result = repr(
            ATable(r,
                   s,
                   offset=0,
                   format_settings=Formatting(wrap='stripes', width=80)))
        result = '\n'.join([line.rstrip() for line in result.splitlines()])
        expected = '''[0]--------------------------
i32                         =
floaties                    =
long_column_name_ugh_and_ugh=
long_value                  =
s                           ='''
        self.assertEqual(expected, result)
        result = repr(
            ATable(r,
                   s,
                   offset=0,
                   format_settings=Formatting(wrap='stripes',
                                              width=80,
                                              with_types=True)))
        result = '\n'.join([line.rstrip() for line in result.splitlines()])
        expected = '''[0]------------------------------
i32:int                         =
floaties:float                  =
long_column_name_ugh_and_ugh:str=
long_value:str                  =
s:str                           ='''
        self.assertEqual(expected, result)
Пример #2
0
 def test_inspect_settings_reset(self):
     settings = Formatting()
     repr1 = repr(settings)
     settings.wrap = 10
     settings.truncate = 8
     settings.round = 2
     settings.width = 90
     settings.margin = 4
     settings.with_types = True
     settings.reset()
     repr2 = repr(settings)
     self.assertEqual(repr1, repr2)
Пример #3
0
 def test_inspect_settings_reset(self):
     settings = Formatting()
     repr1 = repr(settings)
     settings.wrap = 10
     settings.truncate = 8
     settings.round = 2
     settings.width = 90
     settings.margin = 4
     settings.with_types = True
     settings.reset()
     repr2 = repr(settings)
     self.assertEqual(repr1, repr2)
Пример #4
0
    def test_inspection(self):
        result = repr(
            ATable(self.rows1,
                   self.schema1,
                   offset=0,
                   format_settings=Formatting(wrap=2, truncate=40, width=80)))
        result = '\n'.join([line.rstrip() for line in result.splitlines()])
        expected = '''[#]  i32  floaties       long_column_name_ugh_and_ugh
=====================================================
[0]    1  3.14159265358  a
[1]    2    8.014512183  b

[#]  long_value                                s
==================================================
[0]  The sun was shining on the sea,           one
     Shini...
[1]  I'm going down.  Down, down, down, do...  two


[#]  i32  floaties  long_column_name_ugh_and_ugh
================================================
[2]   32       1.0  c

[#]  long_value                                s
=========================================================
[2]  AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA  thirty-two'''
        self.assertEqual(expected, result)
Пример #5
0
    def test_line_numbers(self):
        r = [[x, 'b%s' % x, None] for x in xrange(10)]
        s = self.abc_schema
        result = repr(
            ATable(r,
                   s,
                   offset=92,
                   format_settings=Formatting(wrap=5, width=80)))
        result = '\n'.join([line.rstrip() for line in result.splitlines()])
        expected = '''[##]  a  b   c
=================
[92]  0  b0  None
[93]  1  b1  None
[94]  2  b2  None
[95]  3  b3  None
[96]  4  b4  None


[###]  a  b   c
==================
[97]   5  b5  None
[98]   6  b6  None
[99]   7  b7  None
[100]  8  b8  None
[101]  9  b9  None'''
        self.assertEqual(expected, result)
Пример #6
0
 def test_settings_margin(self):
     settings = Formatting()
     settings.margin = 4
     try:
         settings.margin = 0
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
     try:
         settings.margin = -1
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
     try:
         settings.margin = '12'  # no strings
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
     try:
         settings.margin = 3.5  # no floats
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
Пример #7
0
 def test_settings_wrap(self):
     settings = Formatting()
     settings.wrap = 10
     try:
         settings.wrap = 0
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
     try:
         settings.wrap = 'stripe'
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
     try:
         settings.wrap = 3.5
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
Пример #8
0
    def test_empty(self):
        r = []
        s = self.abc_schema
        result = repr(
            ATable(r,
                   s,
                   offset=0,
                   format_settings=Formatting(wrap=5, width=80)))
        expected = '''[##]  a  b  c
============='''
        self.assertEqual(expected, result)
        result = repr(
            ATable(r,
                   s,
                   offset=0,
                   format_settings=Formatting(wrap=5,
                                              width=80,
                                              with_types=True)))
        expected = '''[##]  a:int  b:unicode  c:unicode
================================='''
        self.assertEqual(expected, result)
Пример #9
0
    def test_wrap_long_str_1(self):
        r = [[
            '12345678901234567890123456789012345678901234567890123456789012345678901234567890'
        ]]
        s = [('s', str)]
        settings = Formatting(wrap=5)
        result = repr(ATable(r, s, offset=0, format_settings=settings))
        result = '\n'.join([line.rstrip() for line in result.splitlines()])
        expected = '''[#]  s
================================================================================
[0]  12345678901234567890123456789012345678901234567890123456789012345678901234567890'''
        self.assertEqual(expected, result)
Пример #10
0
 def test_settings_width(self):
     settings = Formatting()
     settings.width = 4
     try:
         settings.width = 0
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
     try:
         settings.width = '12'  # no strings
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
     try:
         settings.width = 3.5  # no floats
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
Пример #11
0
 def test_settings_truncate(self):
     settings = Formatting()
     settings.truncate = 4
     try:
         settings.truncate = 0
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
     try:
         settings.truncate = '12'  # no strings
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
     try:
         settings.truncate = 3.5  # no floats
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
Пример #12
0
 def test_settings_margin(self):
     settings = Formatting()
     settings.margin = 4
     try:
         settings.margin = 0
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
     try:
         settings.margin = -1
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
     try:
         settings.margin = '12'  # no strings
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
     try:
         settings.margin = 3.5  # no floats
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
Пример #13
0
 def test_settings_round(self):
     settings = Formatting()
     settings.round = 4
     settings.round = 0
     try:
         settings.round = -1
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
     try:
         settings.round = '12'  # no strings
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
     try:
         settings.round = 3.5  # no floats
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
Пример #14
0
    def test_inspect_nones(self):
        schema = [('s', str), ('v', float)]
        rows = [['super', 1.0095], [None, None]]
        result = repr(
            ATable(rows,
                   schema,
                   offset=0,
                   format_settings=Formatting(wrap=2, round=2, truncate=4)))
        result = '\n'.join([line.rstrip() for line in result.splitlines()])
        self.assertEqual(
            """[#]  s     v
===============
[0]  s...  1.01
[1]  None  None""", result)
Пример #15
0
    def test_simple_stripes(self):
        result = repr(
            ATable(self.two_abc_rows,
                   self.abc_schema,
                   offset=0,
                   format_settings=Formatting(wrap='stripes', margin=10)))
        expected = '''[0]
a=1
b=sixteen_16_abced
c=long
[1]
a=2
b=tiny
c=really really really really long'''
        self.assertEqual(expected, result)
Пример #16
0
 def test_settings_with_types(self):
     settings = Formatting()
     settings.with_types = True
     settings.with_types = False
     settings.with_types = None
     try:
         settings.with_types = 0
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
     try:
         settings.with_types = '12'  # no strings
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
     try:
         settings.with_types = 3.5  # no floats
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
Пример #17
0
 def test_settings_width(self):
     settings = Formatting()
     settings.width = 4
     try:
         settings.width = 0
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
     try:
         settings.width = '12'  # no strings
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
     try:
         settings.width = 3.5  # no floats
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
Пример #18
0
 def test_settings_truncate(self):
     settings = Formatting()
     settings.truncate = 4
     try:
         settings.truncate = 0
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
     try:
         settings.truncate = '12'  # no strings
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
     try:
         settings.truncate = 3.5  # no floats
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
Пример #19
0
 def test_settings_wrap(self):
     settings = Formatting()
     settings.wrap = 10
     try:
         settings.wrap = 0
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
     try:
         settings.wrap = 'stripe'
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
     try:
         settings.wrap = 3.5
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
Пример #20
0
 def test_settings_round(self):
     settings = Formatting()
     settings.round = 4
     settings.round = 0
     try:
         settings.round = -1
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
     try:
         settings.round = '12'  # no strings
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
     try:
         settings.round = 3.5  # no floats
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
Пример #21
0
 def test_settings_with_types(self):
     settings = Formatting()
     settings.with_types = True
     settings.with_types = False
     settings.with_types = None
     try:
         settings.with_types = 0
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
     try:
         settings.with_types = '12'  # no strings
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
     try:
         settings.with_types = 3.5  # no floats
     except ValueError:
         pass
     else:
         self.fail("Expected ValueError")
Пример #22
0
 def test_copy(self):
     settings1 = Formatting(truncate=8, width=40)
     settings2 = settings1.copy(round=4, width=80)
     self.assertEqual(8, settings2.truncate)
     self.assertEqual(80, settings2.width)
     self.assertEqual(4, settings2.round)
Пример #23
0
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
#

from sparktk.atable import ATable, Formatting

inspect_settings = Formatting()


def inspect(self,
            n=10,
            offset=0,
            columns=None,
            wrap=inspect_settings._unspecified,
            truncate=inspect_settings._unspecified,
            round=inspect_settings._unspecified,
            width=inspect_settings._unspecified,
            margin=inspect_settings._unspecified,
            with_types=inspect_settings._unspecified):
    """
    Pretty-print of the frame data
Пример #24
0
 def test_copy(self):
     settings1 = Formatting(truncate=8, width=40)
     settings2 = settings1.copy(round=4, width=80)
     self.assertEqual(8, settings2.truncate)
     self.assertEqual(80, settings2.width)
     self.assertEqual(4, settings2.round)