Exemplo n.º 1
0
    def test_getitem_cached(self):
        query = MagicMock(spec=ResolweQuery, _cache=[1, 2, 3], _limit=None, _offset=None)
        result = ResolweQuery.__getitem__(query, 1)
        self.assertEqual(result, 2)

        result = ResolweQuery.__getitem__(query, slice(2))
        self.assertEqual(result, [1, 2])

        # make sure that offset and limit are not set
        self.assertEqual(query._limit, None)
        self.assertEqual(query._offset, None)
Exemplo n.º 2
0
    def test_getitem_cached(self):
        query = MagicMock(
            spec=ResolweQuery, _cache=[1, 2, 3], _limit=None, _offset=None
        )
        result = ResolweQuery.__getitem__(query, 1)
        self.assertEqual(result, 2)

        result = ResolweQuery.__getitem__(query, slice(2))
        self.assertEqual(result, [1, 2])

        # make sure that offset and limit are not set
        self.assertEqual(query._limit, None)
        self.assertEqual(query._offset, None)
Exemplo n.º 3
0
    def test_getitem(self):
        new_query = MagicMock(spec=ResolweQuery)
        query = MagicMock(spec=ResolweQuery, _cache=None, _limit=None, _offset=None,
                          **{'_clone.return_value': new_query})
        ResolweQuery.__getitem__(query, slice(1, 3))
        self.assertEqual(new_query._offset, 1)
        self.assertEqual(new_query._limit, 2)

        new_query.__iter__.return_value = [5]
        result = ResolweQuery.__getitem__(query, 1)
        self.assertEqual(result, 5)
        self.assertEqual(new_query._offset, 1)
        self.assertEqual(new_query._limit, 1)

        new_query.__iter__.return_value = []
        with self.assertRaises(IndexError):
            ResolweQuery.__getitem__(query, 1)
Exemplo n.º 4
0
    def test_getitem(self):
        new_query = MagicMock(spec=ResolweQuery)
        query = MagicMock(spec=ResolweQuery,
                          _cache=None,
                          _limit=None,
                          _offset=None,
                          **{'_clone.return_value': new_query})
        ResolweQuery.__getitem__(query, slice(1, 3))
        self.assertEqual(new_query._offset, 1)
        self.assertEqual(new_query._limit, 2)

        new_query.__iter__.return_value = [5]
        result = ResolweQuery.__getitem__(query, 1)
        self.assertEqual(result, 5)
        self.assertEqual(new_query._offset, 1)
        self.assertEqual(new_query._limit, 1)

        new_query.__iter__.return_value = []
        with self.assertRaises(IndexError):
            ResolweQuery.__getitem__(query, 1)
Exemplo n.º 5
0
    def test_getitem_invalid(self):
        query = MagicMock(spec=ResolweQuery)

        # negative index
        with self.assertRaises(ValueError):
            ResolweQuery.__getitem__(query, -5)

        # negative start
        with self.assertRaises(ValueError):
            ResolweQuery.__getitem__(query, slice(-2, None))

        # negative stop
        with self.assertRaises(ValueError):
            ResolweQuery.__getitem__(query, slice(-1))

        # negative step
        with self.assertRaises(ValueError):
            ResolweQuery.__getitem__(query, slice(1, 5, 2))
Exemplo n.º 6
0
    def test_getitem_invalid(self):
        query = MagicMock(spec=ResolweQuery)

        # negative index
        with self.assertRaises(ValueError):
            ResolweQuery.__getitem__(query, -5)

        # negative start
        with self.assertRaises(ValueError):
            ResolweQuery.__getitem__(query, slice(-2, None))

        # negative stop
        with self.assertRaises(ValueError):
            ResolweQuery.__getitem__(query, slice(-1))

        # negative step
        with self.assertRaises(ValueError):
            ResolweQuery.__getitem__(query, slice(1, 5, 2))