Example #1
0
    def test_get_obj_matching(self):
        """
        Getting an object from the store with conditions
        :return:
        """
        with patch("gzip.open", MagicMock()), patch(
                "os.listdir", MagicMock(return_value=["test_db"])), patch(
                    "csv.reader",
                    MagicMock(return_value=iter([
                        [],
                        ["foo:int", "bar:str", "spam:float"],
                        ["123", "this is test of something", "0.123"],
                        ["234", "another test of stuff", "0.456"],
                    ])),
                ):
            csvdb = CsvDB("/foobar")
            csvdb.open()

            entities = csvdb.get(FoobarEntity, matches={"bar": r"is\stest"})
            assert list == type(entities)
            assert len(entities) == 1

            assert entities[0].foo == 123
            assert entities[0].bar == "this is test of something"
            assert entities[0].spam == 0.123
Example #2
0
    def test_get_object(self):
        """
        Getting an object from the store.
        :return:
        """
        with patch("os.listdir", MagicMock(return_value=["test_db"])), patch(
                "gzip.open", MagicMock()) as gzip_mock_open, patch(
                    "csv.reader",
                    MagicMock(return_value=iter([
                        [],
                        ["foo:int", "bar:str", "spam:float"],
                        ["123", "test", "0.123"],
                        ["234", "another", "0.456"],
                    ])),
                ):
            csvdb = CsvDB("/foobar")
            csvdb.open()
            entities = csvdb.get(FoobarEntity)

            # test the second call to gzip.open, the first is in the open function
            assert gzip_mock_open.call_args_list[1][0][1] == "rt"

            assert list == type(entities)
            assert len(entities) == 2

            assert entities[0].foo == 123
            assert entities[0].bar == "test"
            assert entities[0].spam == 0.123

            assert entities[1].foo == 234
            assert entities[1].bar == "another"
            assert entities[1].spam == 0.456
Example #3
0
    def test_get_object(self):
        '''
        Getting an object from the store.
        :return:
        '''
        with patch("gzip.open", MagicMock()):
            with patch(
                    "csv.reader",
                    MagicMock(return_value=iter([
                        [], ['foo:int', 'bar:str', 'spam:float'],
                        ['123', 'test', '0.123'], ['234', 'another', '0.456']
                    ]))):
                csvdb = CsvDB('/foobar')
                csvdb.open()
                entities = csvdb.get(FoobarEntity)
                assert list == type(entities)
                assert len(entities) == 2

                assert entities[0].foo == 123
                assert entities[0].bar == 'test'
                assert entities[0].spam == 0.123

                assert entities[1].foo == 234
                assert entities[1].bar == 'another'
                assert entities[1].spam == 0.456
    def test_get_obj_matching(self):
        '''
        Getting an object from the store with conditions
        :return:
        '''
        with patch("gzip.open", MagicMock()):
            with patch("csv.reader", MagicMock(return_value=iter([[], ['foo:int', 'bar:str', 'spam:float'],
                                                                  ['123', 'this is test of something', '0.123'],
                                                                  ['234', 'another test of stuff', '0.456']]))):
                csvdb = CsvDB('/foobar')
                csvdb.open()

                entities = csvdb.get(FoobarEntity, matches={'bar': r'is\stest'})
                assert list == type(entities)
                assert len(entities) == 1

                assert entities[0].foo == 123
                assert entities[0].bar == 'this is test of something'
                assert entities[0].spam == 0.123
Example #5
0
    def test_get_obj_less_than(self):
        '''
        Getting an object from the store with conditions
        :return:
        '''
        with patch("gzip.open", MagicMock()), \
                patch("os.listdir", MagicMock(return_value=['test_db'])), \
                patch("csv.reader", MagicMock(return_value=iter([[], ['foo:int', 'bar:str', 'spam:float'],
                                                                 ['123', 'test', '0.123'],
                                                                 ['234', 'another', '0.456']]))):
            csvdb = CsvDB('/foobar')
            csvdb.open()

            entities = csvdb.get(FoobarEntity, lt={'foo': 234})
            assert list == type(entities)
            assert len(entities) == 1

            assert entities[0].foo == 123
            assert entities[0].bar == 'test'
            assert entities[0].spam == 0.123
Example #6
0
    def test_get_object(self):
        '''
        Getting an object from the store.
        :return:
        '''
        with patch("gzip.open", MagicMock()):
            with patch("csv.reader", MagicMock(return_value=iter([[], ['foo:int', 'bar:str', 'spam:float'],
                                                                  ['123', 'test', '0.123'],
                                                                  ['234', 'another', '0.456']]))):
                csvdb = CsvDB('/foobar')
                csvdb.open()
                entities = csvdb.get(FoobarEntity)
                assert list == type(entities)
                assert len(entities) == 2

                assert entities[0].foo == 123
                assert entities[0].bar == 'test'
                assert entities[0].spam == 0.123

                assert entities[1].foo == 234
                assert entities[1].bar == 'another'
                assert entities[1].spam == 0.456