Skip to content

Commit

Permalink
badge test
Browse files Browse the repository at this point in the history
  • Loading branch information
bwallrich committed Apr 26, 2024
1 parent 217191b commit 5dc1d98
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 22 deletions.
33 changes: 24 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# stricto

![example workflow](https://github.com/bwallrich/stricto/actions/workflows/test.yml/coverage.svg)

Strict json structure with schema validation

The way to use is very simple, see [Quickstart](#quickstart) for a basic setup.
Expand Down Expand Up @@ -38,18 +40,21 @@ a.set({
})


print(a.num) # 22
a.name = 666 # -> raise a typeError
print (a) # print like a dict
print(a.address.num) # 22
print(a.address) # { "num" : 22, "street" : "acacia avenue" }

a.name = 666 # -> raise a typeError (must be a string)

a.nicknames.append(666) # -> raise a typeError
print (a) # { "name" : "Edward", ... }

a.nicknames.append(666) # -> raise a typeError (must be a string)
a.nicknames.append("Eddy")
a.nickname[1] # -> Eddy

b=a # b is a reference on a
c=a.copy() # c is a different object : c is a copy

c == b # return True (yes you can test and do operators directly on objects)
c == b # return True (you can test and do operators directly on objects)
b.nicknames.pop()
c == b # return False
```
Expand All @@ -70,7 +75,7 @@ All basic class from python are implemented in ```stricto```.

```python
# example
from stricto import Int
from stricto import Dict, Int

a = Int()
a.set(22) # -> ok
Expand All @@ -79,6 +84,16 @@ a.set("the number of the beast") # raise an error

# WARNING
a = "the number of the beast" # works ! the affectation of "a" change. Now it is a string. This is python.

# Inside a Dict().
test=Dict({
"a" : Int()
})

test.a = 22 # -> ok
test.a = 23.1 # raise an error
test.a = "the number of the beast" # raise an error

```

## json
Expand Down Expand Up @@ -113,8 +128,8 @@ available options for all types ares :

| Option | Default | Description |
| - | - | - |
| ```notNull=True\|False``` | False | cannot be None or inexistent |
| ```required=True\|False``` | False | similar to ```notNull``` |
| ```notNone=True\|False``` | False | cannot be **None** |
| ```required=True\|False``` | False | similar to ```notNone``` |
| ```description="whatever you want"``` | None | a description of this object |
| ```default=666``` | None | the default value |
| ```in=[ 1, 2, 3, 5 ]\|func``` | None | the value must be one of those elements |
Expand All @@ -126,7 +141,7 @@ available options for all types ares :
| ```onChange=func``` | None | similar to ```onchange``` |
| ```set=func``` | None | a read only value, calculated from other .See [set or compute function](#set-or-compute) |
| ```compute=func``` | None | similar to ```set``` |
| ```exists=func``` | None | a function to say if the object "exists", depending on values from other attributs. See [exists](#exists) for details |
| ```exists=func``` | True | a function to say if the object "exists", depending on values from other attributs. See [exists](#exists) for details |

See [functions](#functions) for mor details and examples how to use them.

Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
[project]
name = "stricto"
version = "0.0.1"
version = "0.0.2"
authors = [
{ name="Bertrand Wallrich", email="Bertrand.Wallrich@inria.fr" },
]
description = "Strict Dict (json) with schema validation embedded"
readme = "README.md"
requires-python = ">=3.8"
license = {file = "LICENSE"}
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]

[project.urls]
GitHub = "https://github.com/NiziL/esnpy"
Homepage = "https://github.com/bwallrich/stricto"
Issues = "https://github.com/bwallrich/stricto/issues"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
build-backend = "hatchling.build"
6 changes: 3 additions & 3 deletions stricto/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, **kwargs):
description : A tring to describe the object
default : The default value
notNull : (boolean) must be required or not
notNone : (boolean) must be required or not
"""
self.root = None
Expand All @@ -26,7 +26,7 @@ def __init__(self, **kwargs):
self._value = None
self._old_value = None
self._descrition = kwargs.pop("description", None)
self._not_null = kwargs.pop("notNull", kwargs.pop("required", False))
self._not_none = kwargs.pop("notNone", kwargs.pop("required", False))
self._union = kwargs.pop("union", kwargs.pop("in", None))
self.currently_doing_autoset = False
constraint = kwargs.pop("constraint", kwargs.pop("constraints", []))
Expand Down Expand Up @@ -332,7 +332,7 @@ def check(self, value):

# handle the None value
if corrected_value is None:
if self._not_null is True:
if self._not_none is True:
raise Error(ErrorType.NULL, "Cannot be empty", self.path_name())
return True

Expand Down
4 changes: 2 additions & 2 deletions tests/test_bool.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def test_not_null(self):
Test notnull for a bool
"""
with self.assertRaises(Error) as e:
a = Bool(notNull=True)
a = Bool(notNone=True)
self.assertEqual(e.exception.message, "Cannot be empty")
a = Bool(notNull=True, default= True)
a = Bool(notNone=True, default= True)
with self.assertRaises(Error) as e:
a.set(None)
self.assertEqual(e.exception.message, "Cannot be empty")
Expand Down
4 changes: 2 additions & 2 deletions tests/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def test_list_none(self):
Test notnull value
"""
with self.assertRaises(Error) as e:
a = List(Int(), notNull=True)
a = List(Int(), notNone=True)
self.assertEqual(e.exception.message, "Cannot be empty")
a = List(Int(), notNull=True, default=[])
a = List(Int(), notNone=True, default=[])
with self.assertRaises(Error) as e:
a.set(None)
self.assertEqual(e.exception.message, "Cannot be empty")
Expand Down
8 changes: 4 additions & 4 deletions tests/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ def test_not_null(self):
String not null
"""
with self.assertRaises(Error) as e:
a = String(notNull=True)
a = String(notNone=True)
self.assertEqual(e.exception.message, "Cannot be empty")
a = String(notNull=True, default="")
a = String(notNone=True, default="")
with self.assertRaises(Error) as e:
a.set(None)
self.assertEqual(e.exception.message, "Cannot be empty")
Expand All @@ -101,14 +101,14 @@ def test_default(self):
"""
test default value
"""
a = String(notNull=True, default="yoyo")
a = String(notNone=True, default="yoyo")
self.assertEqual(a, "yoyo")

def test_count(self):
"""
test count function
"""
a = String(notNull=True, default="yoyo")
a = String(notNone=True, default="yoyo")
self.assertEqual(a.count("y"), 2)

def test_regexp(self):
Expand Down

0 comments on commit 5dc1d98

Please sign in to comment.