-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
137 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "dictdatabase" | ||
version = "2.1.2" | ||
version = "2.1.3" | ||
repository = "https://github.com/mkrd/DictDataBase" | ||
description = "Easy-to-use database using dicts" | ||
authors = ["Marcel Kröker <[email protected]>"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
import dictdatabase as DDB | ||
import pytest | ||
|
||
|
||
def test_delete(env, use_compression, use_orjson, sort_keys, indent): | ||
DDB.at("test_delete").create({"a": 1}, force_overwrite=True) | ||
assert DDB.at("test_delete").read() == {"a": 1} | ||
DDB.at("test_delete").delete() | ||
assert DDB.at("test_delete").read() is None | ||
DDB.at("test_delete").create({"a": 1}, force_overwrite=True) | ||
assert DDB.at("test_delete").read() == {"a": 1} | ||
DDB.at("test_delete").delete() | ||
assert DDB.at("test_delete").read() is None | ||
|
||
with pytest.raises(RuntimeError): | ||
DDB.at("test_delete", where=lambda k, v: True).delete() | ||
|
||
with pytest.raises(RuntimeError): | ||
DDB.at("test_delete", key="any").delete() | ||
|
||
|
||
|
||
def test_delete_nonexistent(env, use_compression, use_orjson, sort_keys, indent): | ||
DDB.at("test_delete_nonexistent").delete() | ||
DDB.at("test_delete_nonexistent").delete() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import dictdatabase as DDB | ||
import pytest | ||
|
||
|
||
def test_exists(env, use_compression, use_orjson, sort_keys, indent): | ||
DDB.at("test_exists").create({"a": 1}, force_overwrite=True) | ||
assert DDB.at("test_exists").exists() | ||
assert not DDB.at("test_exists/nonexistent").exists() | ||
assert DDB.at("test_exists", key="a").exists() | ||
assert not DDB.at("test_exists", key="b").exists() | ||
with pytest.raises(RuntimeError): | ||
DDB.at("test_exists", where=lambda k, v: True).exists() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
import dictdatabase as DDB | ||
import orjson | ||
import json | ||
from dictdatabase import utils, io_unsafe, config | ||
|
||
data = { | ||
'a': 1, | ||
'b': { | ||
'c': 2, | ||
"cl": [1, "\\"], | ||
'd': { | ||
'e': 3, | ||
"el": [1, "\\"], | ||
} | ||
}, | ||
"l": [1, "\\"], | ||
} | ||
|
||
|
||
def string_dump(db: dict): | ||
if not config.use_orjson: | ||
return json.dumps(db, indent=config.indent, sort_keys=config.sort_keys) | ||
option = orjson.OPT_INDENT_2 if config.indent else 0 | ||
option |= orjson.OPT_SORT_KEYS if config.sort_keys else 0 | ||
return orjson.dumps(db, option=option) | ||
|
||
|
||
|
||
|
||
def test_indentation(env, use_compression, use_orjson, sort_keys, indent): | ||
DDB.at("test_indentation").create(data, force_overwrite=True) | ||
|
||
with DDB.at("test_indentation", key="b").session() as (session, db_b): | ||
db_b["c"] = 3 | ||
session.write() | ||
data["b"]["c"] = 3 | ||
if use_orjson: | ||
assert io_unsafe.read_file("test_indentation", as_bytes=True) == string_dump(data) | ||
else: | ||
assert io_unsafe.read_file("test_indentation") == string_dump(data) | ||
|
||
|
||
with DDB.at("test_indentation", key="d").session() as (session, db_d): | ||
db_d["e"] = 4 | ||
session.write() | ||
data["b"]["d"]["e"] = 4 | ||
if use_orjson: | ||
assert io_unsafe.read_file("test_indentation", as_bytes=True) == string_dump(data) | ||
else: | ||
assert io_unsafe.read_file("test_indentation") == string_dump(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters