Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
force-bdss
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Adham Hashibon
force-bdss
Commits
a05d9e5d
Commit
a05d9e5d
authored
6 years ago
by
Stefano Borini
Browse files
Options
Downloads
Patches
Plain Diff
Adds positive int trait
parent
61b6a8f8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!164
Adds positive int trait
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
force_bdss/api.py
+1
-1
1 addition, 1 deletion
force_bdss/api.py
force_bdss/local_traits.py
+17
-1
17 additions, 1 deletion
force_bdss/local_traits.py
force_bdss/tests/test_local_traits.py
+12
-1
12 additions, 1 deletion
force_bdss/tests/test_local_traits.py
with
30 additions
and
3 deletions
force_bdss/api.py
+
1
−
1
View file @
a05d9e5d
...
...
@@ -43,4 +43,4 @@ from .ui_hooks.i_ui_hooks_factory import IUIHooksFactory # noqa
from
.ui_hooks.base_ui_hooks_factory
import
BaseUIHooksFactory
# noqa
from
.ui_hooks.base_ui_hooks_manager
import
BaseUIHooksManager
# noqa
from
.local_traits
import
Identifier
# noqa
from
.local_traits
import
Identifier
,
PositiveInt
# noqa
This diff is collapsed.
Click to expand it.
force_bdss/local_traits.py
+
17
−
1
View file @
a05d9e5d
from
traits.api
import
Regex
,
String
from
traits.api
import
Regex
,
String
,
BaseInt
#: Used for variable names, but allow also empty string as it's the default
#: case and it will be present if the workflow is saved before actually
...
...
@@ -8,3 +8,19 @@ Identifier = Regex(regex="(^[^\d\W]\w*\Z|^\Z)")
#: Identifies a CUBA type with its key. At the moment a String with
#: no validation, but will come later.
CUBAType
=
String
()
class
PositiveInt
(
BaseInt
):
"""
A positive integer trait.
"""
info_text
=
'
a positive integer
'
default_value
=
1
def
validate
(
self
,
object
,
name
,
value
):
int_value
=
super
(
PositiveInt
,
self
).
validate
(
object
,
name
,
value
)
if
int_value
>
0
:
return
int_value
self
.
error
(
object
,
name
,
value
)
This diff is collapsed.
Click to expand it.
force_bdss/tests/test_local_traits.py
+
12
−
1
View file @
a05d9e5d
import
unittest
from
traits.api
import
HasStrictTraits
,
TraitError
from
force_bdss.local_traits
import
Identifier
,
CUBAType
from
force_bdss.local_traits
import
Identifier
,
CUBAType
,
PositiveInt
class
Traited
(
HasStrictTraits
):
val
=
Identifier
()
cuba
=
CUBAType
()
positive_int
=
PositiveInt
()
class
TestLocalTraits
(
unittest
.
TestCase
):
...
...
@@ -25,3 +26,13 @@ class TestLocalTraits(unittest.TestCase):
c
=
Traited
()
c
.
cuba
=
"
PRESSURE
"
self
.
assertEqual
(
c
.
cuba
,
"
PRESSURE
"
)
def
test_positive_int
(
self
):
c
=
Traited
()
with
self
.
assertRaises
(
TraitError
):
c
.
positive_int
=
0
with
self
.
assertRaises
(
TraitError
):
c
.
positive_int
=
-
1
c
.
positive_int
=
3
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment