Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/test_storage.py
# Copyright (C) 2015-2019 The Software Heritage developers | # Copyright (C) 2015-2019 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import copy | import copy | ||||
from contextlib import contextmanager | |||||
import datetime | import datetime | ||||
import itertools | import itertools | ||||
import queue | import queue | ||||
import random | import random | ||||
import threading | import threading | ||||
import unittest | import unittest | ||||
from collections import defaultdict | from collections import defaultdict | ||||
from unittest.mock import Mock, patch | from unittest.mock import Mock, patch | ||||
Show All 26 Lines | def setUp(self): | ||||
self.maxDiff = None | self.maxDiff = None | ||||
def tearDown(self): | def tearDown(self): | ||||
self.reset_storage() | self.reset_storage() | ||||
if hasattr(self.storage, '_pool') and self.storage._pool: | if hasattr(self.storage, '_pool') and self.storage._pool: | ||||
self.storage._pool.closeall() | self.storage._pool.closeall() | ||||
super().tearDown() | super().tearDown() | ||||
def get_db(self): | |||||
return self.storage.db() | |||||
@contextmanager | |||||
def db_transaction(self): | |||||
with self.get_db() as db: | |||||
with db.transaction() as cur: | |||||
yield db, cur | |||||
class TestStorageData: | class TestStorageData: | ||||
def setUp(self, *args, **kwargs): | def setUp(self, *args, **kwargs): | ||||
super().setUp(*args, **kwargs) | super().setUp(*args, **kwargs) | ||||
self.cont = { | self.cont = { | ||||
'data': b'42\n', | 'data': b'42\n', | ||||
'length': 3, | 'length': 3, | ||||
▲ Show 20 Lines • Show All 4,095 Lines • Show Last 20 Lines |