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
d305d31f
Unverified
Commit
d305d31f
authored
6 years ago
by
Stefano Borini
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #164 from force-h2020/positive-int-trait
Adds positive int trait
parents
2b03fb7b
a05d9e5d
No related branches found
No related tags found
No related merge requests found
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 @
d305d31f
...
@@ -45,4 +45,4 @@ from .ui_hooks.i_ui_hooks_factory import IUIHooksFactory # noqa
...
@@ -45,4 +45,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_factory
import
BaseUIHooksFactory
# noqa
from
.ui_hooks.base_ui_hooks_manager
import
BaseUIHooksManager
# 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 @
d305d31f
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
#: 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
#: 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)")
...
@@ -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
#: Identifies a CUBA type with its key. At the moment a String with
#: no validation, but will come later.
#: no validation, but will come later.
CUBAType
=
String
()
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 @
d305d31f
import
unittest
import
unittest
from
traits.api
import
HasStrictTraits
,
TraitError
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
):
class
Traited
(
HasStrictTraits
):
val
=
Identifier
()
val
=
Identifier
()
cuba
=
CUBAType
()
cuba
=
CUBAType
()
positive_int
=
PositiveInt
()
class
TestLocalTraits
(
unittest
.
TestCase
):
class
TestLocalTraits
(
unittest
.
TestCase
):
...
@@ -25,3 +26,13 @@ class TestLocalTraits(unittest.TestCase):
...
@@ -25,3 +26,13 @@ class TestLocalTraits(unittest.TestCase):
c
=
Traited
()
c
=
Traited
()
c
.
cuba
=
"
PRESSURE
"
c
.
cuba
=
"
PRESSURE
"
self
.
assertEqual
(
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