Skip to content

Commit

Permalink
Tests: Skip incompatible tests when ujson is installed
Browse files Browse the repository at this point in the history
Closes #262
  • Loading branch information
msiemens committed May 17, 2019
1 parent b25d02e commit d54d6cd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
8 changes: 8 additions & 0 deletions tests/test_storages.py
Expand Up @@ -13,6 +13,13 @@

random.seed()

try:
import ujson as json
except ImportError:
HAS_UJSON = False
else:
HAS_UJSON = True

doc = {'none': [None, None], 'int': 42, 'float': 3.1415899999999999,
'list': ['LITE', 'RES_ACID', 'SUS_DEXT'],
'dict': {'hp': 13, 'sp': 5},
Expand All @@ -30,6 +37,7 @@ def test_json(tmpdir):
storage.close()


@pytest.mark.skipif(HAS_UJSON, reason="not compatible with ujson")
def test_json_kwargs(tmpdir):
db_file = tmpdir.join('test.db')
db = TinyDB(str(db_file), sort_keys=True, indent=4, separators=(',', ': '))
Expand Down
27 changes: 25 additions & 2 deletions tests/test_tinydb.py
Expand Up @@ -4,10 +4,17 @@

import pytest

from tinydb import TinyDB, where
from tinydb import TinyDB, where, Query
from tinydb.middlewares import Middleware, CachingMiddleware
from tinydb.storages import MemoryStorage

try:
import ujson as json
except ImportError:
HAS_UJSON = False
else:
HAS_UJSON = True


def test_purge(db):
db.purge()
Expand Down Expand Up @@ -539,6 +546,7 @@ def test_insert_string(tmpdir):
_db.insert({'int': 3}) # Does not fail


@pytest.mark.skipif(HAS_UJSON, reason="not compatible with ujson")
def test_insert_invalid_dict(tmpdir):
path = str(tmpdir.join('db.json'))

Expand All @@ -547,7 +555,7 @@ def test_insert_invalid_dict(tmpdir):
_db.insert_multiple(data)

with pytest.raises(TypeError):
_db.insert({'int': {'bark'}}) # Fails
_db.insert({'int': _db}) # Fails

assert data == _db.all()

Expand Down Expand Up @@ -780,6 +788,21 @@ def test_repr(tmpdir):
repr(TinyDB(path)))


def test_delete(tmpdir):
path = str(tmpdir.join('db.json'))

db = TinyDB(path, ensure_ascii=False)
q = Query()
db.insert({'network': {'id': '114', 'name': 'ok', 'rpc': 'dac',
'ticker': 'mkay'}})
assert db.search(q.network.id == '114') == [
{'network': {'id': '114', 'name': 'ok', 'rpc': 'dac',
'ticker': 'mkay'}}
]
db.remove(q.network.id == '114')
assert db.search(q.network.id == '114') == []


def test_insert_multiple_with_single_dict(db):
with pytest.raises(ValueError):
d = {'first': 'John', 'last': 'smith'}
Expand Down

0 comments on commit d54d6cd

Please sign in to comment.