Example #1
0
    def test_data_frame(self):
        """Should render data Frame"""
        df = pd.DataFrame([{
            'a': 1,
            'b': 'hello',
            'c': True,
            'd': date(2016, 9, 9)
        }, {
            'a': 1,
            'b': 'hello',
            'c': True,
            'd': date(2016, 9, 9)
        }, {
            'a': 1,
            'b': 'hello',
            'c': True,
            'd': date(2016, 9, 9)
        }, {
            'a': 1,
            'b': 'hello',
            'c': True,
            'd': date(2016, 9, 9)
        }])

        result = texts.head(df, 3)
        self.assertGreater(len(result), 1)

        result = texts.tail(df, 3)
        self.assertGreater(len(result), 1)
Example #2
0
    def test_list(self):
        """Should render list"""
        source = [{
            'a': 1,
            'b': 'hello',
            'c': True,
            'd': date(2016, 9, 9)
        }, {
            'a': 1,
            'b': 'hello',
            'c': True,
            'd': date(2016, 9, 9)
        }, {
            'a': 1,
            'b': 'hello',
            'c': True,
            'd': date(2016, 9, 9)
        }, {
            'a': 1,
            'b': 'hello',
            'c': True,
            'd': date(2016, 9, 9)
        }]

        result = texts.head(source, 3)
        self.assertGreater(len(result), 1)

        result = texts.tail(source, 3)
        self.assertGreater(len(result), 1)
Example #3
0
 def test_tail_mock(self):
     """Should show last 3 lines of mock object"""
     target = MagicMock()
     target.tail.side_effect = ValueError('FAKE')
     target.__len__.return_value = 10
     target.__iter__.return_value = range(10)
     result = texts.tail(target, 3)
     self.assertLess(0, len(result), 'Result should not be empty')
Example #4
0
    def test_dict(self):
        """Should render dictionary"""
        source = {'a': 1, 'b': 'hello', 'c': True, 'd': date(2016, 9, 9)}

        result = texts.head(source, 2)
        self.assertGreater(len(result), 1)

        result = texts.tail(source, 2)
        self.assertGreater(len(result), 1)
Example #5
0
    def test_dict(self):
        """Should render dictionary"""
        source = {'a': 1, 'b': 'hello', 'c': True, 'd': date(2016, 9, 9)}

        result = texts.head(source, 2)
        self.assertGreater(len(result), 1)

        result = texts.tail(source, 2)
        self.assertGreater(len(result), 1)
Example #6
0
    def test_array(self):
        """Should render array"""
        array = np.ndarray([1, 2, 3, 4, 5, 6])

        result = texts.head(array, 2)
        self.assertGreater(len(result), 1)

        result = texts.tail(array, 2)
        self.assertGreater(len(result), 1)
Example #7
0
    def test_array(self):
        """Should render array"""
        array = np.ndarray([1, 2, 3, 4, 5, 6])

        result = texts.head(array, 2)
        self.assertGreater(len(result), 1)

        result = texts.tail(array, 2)
        self.assertGreater(len(result), 1)
Example #8
0
    def test_object(self):
        """Should render object"""
        class TestObject(object):
            def __str__(self):
                return 'a\nb\nc\nd\ne'

        result = texts.head(TestObject(), 2)
        self.assertGreater(len(result), 1)

        result = texts.tail(TestObject(), 2)
        self.assertGreater(len(result), 1)
Example #9
0
 def test_tail_mock(self):
     """Should show last 3 lines of mock object"""
     target = MagicMock()
     target.tail.side_effect = ValueError('FAKE')
     target.__len__.return_value = 10
     target.__iter__.return_value = range(10)
     result = texts.tail(target, 3)
     self.assertLess(
         0, len(result),
         'Result should not be empty'
     )
Example #10
0
    def test_object(self):
        """Should render object"""

        class TestObject(object):

            def __str__(self):
                return 'a\nb\nc\nd\ne'

        result = texts.head(TestObject(), 2)
        self.assertGreater(len(result), 1)

        result = texts.tail(TestObject(), 2)
        self.assertGreater(len(result), 1)
Example #11
0
    def test_data_frame(self):
        """Should render data Frame"""
        df = pd.DataFrame([
            {'a': 1, 'b': 'hello', 'c': True, 'd': date(2016, 9, 9)},
            {'a': 1, 'b': 'hello', 'c': True, 'd': date(2016, 9, 9)},
            {'a': 1, 'b': 'hello', 'c': True, 'd': date(2016, 9, 9)},
            {'a': 1, 'b': 'hello', 'c': True, 'd': date(2016, 9, 9)}
        ])

        result = texts.head(df, 3)
        self.assertGreater(len(result), 1)

        result = texts.tail(df, 3)
        self.assertGreater(len(result), 1)
Example #12
0
    def test_list(self):
        """Should render list"""
        source = [
            {'a': 1, 'b': 'hello', 'c': True, 'd': date(2016, 9, 9)},
            {'a': 1, 'b': 'hello', 'c': True, 'd': date(2016, 9, 9)},
            {'a': 1, 'b': 'hello', 'c': True, 'd': date(2016, 9, 9)},
            {'a': 1, 'b': 'hello', 'c': True, 'd': date(2016, 9, 9)}
        ]

        result = texts.head(source, 3)
        self.assertGreater(len(result), 1)

        result = texts.tail(source, 3)
        self.assertGreater(len(result), 1)
Example #13
0
def tail(source, count: int = 5):
    """
    The opposite of the head function. Displays the last *count* elements of
    the *source* object.

    :param source:
        DataFrames will show the last *count* rows of that DataFrame. A list,
        tuple or other iterable, will show the last *count* rows. Dictionaries
        will show *count* keys from the dictionary, which will be randomly
        selected unless you are using an OrderedDict. Strings will show the
        last *count* characters.
    :param count:
        The number of elements to show from the source.
    """

    _get_report().append_body(render_texts.tail(source, count=count))
Example #14
0
def tail(source, count: int = 5):
    """
    The opposite of the head function. Displays the last *count* elements of
    the *source* object.

    :param source:
        DataFrames will show the last *count* rows of that DataFrame. A list,
        tuple or other iterable, will show the last *count* rows. Dictionaries
        will show *count* keys from the dictionary, which will be randomly
        selected unless you are using an OrderedDict. Strings will show the
        last *count* characters.
    :param count:
        The number of elements to show from the source.
    """
    r = _get_report()
    r.append_body(render_texts.tail(source, count=count))
    r.stdout_interceptor.write_source('[ADDED] Tail\n')
Example #15
0
 def test_tail_string(self):
     """Should show last 3 lines of string"""
     source = 'a\nb\nc\nd\ne\nf'
     result = texts.tail(source, 3)
     self.assertTrue(0 < result.find('d\ne\nf'))
Example #16
0
 def test_tail_empty_data_frame(self):
     """
     Should return an empty string when there are no rows to head.
     """
     result = texts.tail(pd.DataFrame([]))
     self.assertEqual('', result)
Example #17
0
 def test_tail_no_rows(self):
     """Should return an empty string when no rows are set for display."""
     result = texts.tail(None, 0)
     self.assertEqual('', result)
Example #18
0
 def test_tail_no_rows(self):
     """Should return an empty string when no rows are set for display."""
     result = texts.tail(None, 0)
     self.assertEqual('', result)
Example #19
0
 def test_tail_string(self):
     """Should show last 3 lines of string"""
     source = 'a\nb\nc\nd\ne\nf'
     result = texts.tail(source, 3)
     self.assertTrue(0 < result.find('d\ne\nf'))
Example #20
0
 def test_tail_empty_data_frame(self):
     """
     Should return an empty string when there are no rows to head.
     """
     result = texts.tail(pd.DataFrame([]))
     self.assertEqual('', result)