Skip to content

Commit

Permalink
Merge branch 'main' into fix-definitions-ordering
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Challis <[email protected]>
  • Loading branch information
ghandic authored Dec 3, 2023
2 parents c345d4e + 1d94ad1 commit 0798188
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/mkdoc-gh-pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
name: Deploy docs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
python-version: ["3.8", "3.9"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/cache@v3
id: cache
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
Expand Down
43 changes: 23 additions & 20 deletions jsf/tests/test_default_fake.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import re
from typing import Optional

import jwt # pants: no-infer-dep

Expand Down Expand Up @@ -311,34 +312,36 @@ def test_fake_object_pattern_properties(TestData):
assert len(all_int_names) > 0


def assert_regex(pattern: str, string: str, info: Optional[str]) -> None:
assert bool(re.match(pattern, string)), (string, info)


def test_fake_string_format(TestData):
with open(TestData / "string-format.json", "r") as file:
schema = json.load(file)
p = JSF(schema)

assert isinstance(p.generate(), dict)
fake_data = [p.generate() for _ in range(10)]
assert all(bool(re.match(r".*@.*", d["email"])) for d in fake_data), fake_data
assert all(bool(re.match(r".*@.*", d["idn-email"])) for d in fake_data), fake_data
assert all(
bool(re.match(r"\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}\+\d{2}\:\d{2}", d["date-time"])) for d in fake_data
), fake_data
assert all(bool(re.match(r"\d{4}-\d{2}-\d{2}", d["date"])) for d in fake_data), fake_data
assert all(
bool(
re.match(
r"^(-?)P(?=\d|T\d)(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)W)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?)?$",
d["duration"],
)

for d in fake_data:
assert_regex(r".*@.*", d["email"], "email")
assert_regex(r".*@.*", d["idn-email"], "idn-email")
assert_regex(
r"\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}\.*\d*[-\+]\d{2}\:\d{2}",
d["date-time"],
"date-time",
)
assert_regex(r"\d{4}-\d{2}-\d{2}", d["date"], "date")
assert_regex(
r"^(-?)P(?=\d|T\d)(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)W)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?)?$",
d["duration"],
"duration",
)
for d in fake_data
), fake_data
assert all(bool(re.match(r"\d{2}\:\d{2}\:\d{2}\+\d{2}\:\d{2}", d["time"])) for d in fake_data), fake_data
assert all(bool(re.match(r"[a-zA-Z0-9+-\.]{1,33}\.[a-z]{2,4}", d["hostname"])) for d in fake_data)
assert all(bool(re.match(r"[a-zA-Z0-9+-\.]{1,33}\.[a-z]{2,4}", d["idn-hostname"])) for d in fake_data)
assert all(bool(re.match(r"[a-f0-9]{0,4}(:[a-f0-9]{0,4}){7}", d["ipv6"])) for d in fake_data), [
d["ipv6"] for d in fake_data
]
assert_regex(r"\d{2}\:\d{2}\:\d{2}\.*\d*[-\+]\d{2}\:\d{2}", d["time"], "time")
assert_regex(r"[a-zA-Z0-9+-\.]{1,33}\.[a-z]{2,4}", d["hostname"], "hostname")
assert_regex(r"[a-zA-Z0-9+-\.]{1,33}\.[a-z]{2,4}", d["idn-hostname"], "idn-hostname")
assert_regex(r"[a-f0-9]{0,4}(:[a-f0-9]{0,4}){7}", d["ipv6"], "ipv6")

# TODO: add more regex tests
# "ipv4"
Expand Down

0 comments on commit 0798188

Please sign in to comment.