Created
June 7, 2018 18:09
-
-
Save deckar01/628bedb6b9538f6d6c979a9dcfe6307a to your computer and use it in GitHub Desktop.
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
diff --git a/benchmarks/run.py b/benchmarks/run.py | |
index c1209e9..9f5681f 100644 | |
--- a/benchmarks/run.py | |
+++ b/benchmarks/run.py | |
@@ -15,6 +15,7 @@ from pathlib import Path | |
from statistics import StatisticsError, mean | |
from statistics import stdev as stdev_ | |
+from test_marsha import TestMarsha | |
from test_pydantic import TestPydantic | |
from test_trafaret import TestTrafaret | |
from test_drf import TestDRF | |
@@ -131,7 +132,7 @@ def main(): | |
tests = [TestPydantic] | |
else: | |
# in order of performance for csv | |
- tests = [TestPydantic, TestToastedMarshmallow, TestMarshmallow, TestTrafaret, TestDRF] | |
+ tests = [TestMarsha, TestPydantic, TestToastedMarshmallow, TestMarshmallow, TestTrafaret, TestDRF] | |
repeats = int(os.getenv('BENCHMARK_REPEATS', '5')) | |
results = [] | |
@@ -188,6 +189,7 @@ def diff(): | |
allow_extra = True | |
pydantic = TestPydantic(allow_extra) | |
others = [ | |
+ TestMarsha(allow_extra), | |
TestTrafaret(allow_extra), | |
TestDRF(allow_extra), | |
TestMarshmallow(allow_extra), | |
diff --git a/benchmarks/test_marsha.py b/benchmarks/test_marsha.py | |
new file mode 100644 | |
index 0000000..b8dba2e | |
--- /dev/null | |
+++ b/benchmarks/test_marsha.py | |
@@ -0,0 +1,51 @@ | |
+from datetime import datetime | |
+from typing import List, Optional | |
+ | |
+import marsha | |
+ | |
+class TestMarsha: | |
+ package = 'marsha' | |
+ | |
+ def __init__(self, allow_extra): | |
+ | |
+ iso_date = marsha.type(marsha.formats.DateString.format('%Y-%m-%dT%H:%M:%S')) | |
+ | |
+ text = marsha.type(marsha.formats.LimitedString.limit(max=255)) | |
+ url = marsha.type(marsha.formats.LimitedString.limit(max=1023)) | |
+ captcha = marsha.type(marsha.formats.LimitedString.limit(min=20, max=1000)) | |
+ | |
+ @marsha.schema() | |
+ class Location(marsha.Object): | |
+ latitude: Optional[float] | |
+ longitude: Optional[float] | |
+ | |
+ @marsha.schema(ignore_extra=allow_extra) | |
+ class Skill(marsha.Object): | |
+ subject: str | |
+ subject_id: int | |
+ category: str | |
+ qual_level: str | |
+ qual_level_id: int | |
+ qual_level_ranking: float = 0 | |
+ | |
+ @marsha.schema() | |
+ class Model(marsha.Object): | |
+ id: int | |
+ client_name: text | |
+ sort_index: float | |
+ # client_email: EmailStr = None | |
+ client_phone: Optional[text] = None | |
+ location: Optional[Location] | |
+ contractor: Optional[marsha.types.positive_integer_string] | |
+ upstream_http_referrer: Optional[url] = None | |
+ grecaptcha_response: captcha | |
+ last_updated: Optional[iso_date] | |
+ skills: List[Skill] = [] | |
+ | |
+ self.model = Model | |
+ | |
+ def validate(self, data): | |
+ try: | |
+ return True, marsha.load(data, self.model) | |
+ except (TypeError, ValueError) as e: | |
+ return False, str(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment