Esempio n. 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)
Esempio n. 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)
Esempio n. 3
0
 def test_head_mock(self):
     """Should show 3 lines of mock object"""
     target = MagicMock()
     target.head.side_effect = ValueError('FAKE')
     target.__len__.return_value = 10
     target.__iter__.return_value = range(10)
     result = texts.head(target, 3)
     self.assertLess(0, len(result), 'Result should not be empty')
Esempio n. 4
0
 def test_head_mock(self):
     """Should show 3 lines of mock object"""
     target = MagicMock()
     target.head.side_effect = ValueError('FAKE')
     target.__len__.return_value = 10
     target.__iter__.return_value = range(10)
     result = texts.head(target, 3)
     self.assertLess(0, len(result), 'Result should not be empty')
Esempio n. 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)
Esempio n. 6
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)
Esempio n. 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)
Esempio n. 8
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)
Esempio n. 9
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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 13
0
def head(source, count: int = 5):
    """
    Displays a specified number of elements in a source object of many
    different possible types.

    :param source:
        DataFrames will show *count* rows of that DataFrame. A list, tuple or
        other iterable, will show the first *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 first
        *count* characters.
    :param count:
        The number of elements to show from the source.
    """

    _get_report().append_body(render_texts.head(source, count=count))
Esempio n. 14
0
def head(source, count: int = 5):
    """
    Displays a specified number of elements in a source object of many
    different possible types.

    :param source:
        DataFrames will show *count* rows of that DataFrame. A list, tuple or
        other iterable, will show the first *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 first
        *count* characters.
    :param count:
        The number of elements to show from the source.
    """
    r = _get_report()
    r.append_body(render_texts.head(source, count=count))
    r.stdout_interceptor.write_source('[ADDED] Head\n')
Esempio n. 15
0
 def test_head_string(self):
     """Should show first 3 lines of string"""
     source = 'a\nb\nc\nd\ne\nf'
     result = texts.head(source, 3)
     self.assertTrue(0 < result.find('a\nb\nc'))
Esempio n. 16
0
 def test_head_empty_data_frame(self):
     """
     Should return an empty string when there are no rows to head.
     """
     result = texts.head(pd.DataFrame([]))
     self.assertEqual('', result)
Esempio n. 17
0
 def test_head_no_rows(self):
     """Should return an empty string when no rows are set for display."""
     result = texts.head(None, 0)
     self.assertEqual('', result)
Esempio n. 18
0
 def test_head_no_rows(self):
     """Should return an empty string when no rows are set for display."""
     result = texts.head(None, 0)
     self.assertEqual('', result)
Esempio n. 19
0
 def test_head_empty_data_frame(self):
     """
     Should return an empty string when there are no rows to head.
     """
     result = texts.head(pd.DataFrame([]))
     self.assertEqual('', result)
Esempio n. 20
0
 def test_head_string(self):
     """Should show first 3 lines of string"""
     source = 'a\nb\nc\nd\ne\nf'
     result = texts.head(source, 3)
     self.assertTrue(0 < result.find('a\nb\nc'))