Files
conflict-set/test_conflict_set.py

41 lines
1.2 KiB
Python

from conflict_set import *
def test_conflict_set():
with ConflictSet() as cs:
before = cs.getBytes()
key = b"a key"
cs.addWrites(1, write(key))
assert cs.getBytes() - before > 0
assert cs.check(read(0, key)) == [Result.CONFLICT]
cs.setOldestVersion(1)
assert cs.check(read(0, key)) == [Result.TOO_OLD]
if __name__ == "__main__":
# budget "pytest" for ctest integration without pulling in a dependency. You can of course still use pytest in local development.
import argparse
import inspect
import sys
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest="command")
list_parser = subparsers.add_parser("list")
test_parser = subparsers.add_parser("test")
test_parser.add_argument("test")
args = parser.parse_args()
if args.command == "list":
sys.stdout.write(
";".join(
name[5:]
for name in dir()
if name.startswith("test_")
and inspect.isfunction(getattr(sys.modules[__name__], name))
)
)
elif args.command == "test":
globals()["test_" + args.test]()