Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
CaosDB Crawler
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue 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
caosdb
Software
CaosDB Crawler
Commits
9713d134
Commit
9713d134
authored
1 year ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
ENH: add new transform function: replace
parent
9affdce8
Branches
Branches containing commit
Tags
Tags containing commit
3 merge requests
!160
STY: styling
,
!139
ENH: add new transform function: replace
,
!137
F overview
Pipeline
#46122
canceled
1 year ago
Stage: info
Stage: setup
Stage: cert
Stage: style
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/caoscrawler/default_transformers.yml
+3
-0
3 additions, 0 deletions
src/caoscrawler/default_transformers.yml
src/caoscrawler/transformer_functions.py
+11
-0
11 additions, 0 deletions
src/caoscrawler/transformer_functions.py
unittests/test_converters.py
+18
-1
18 additions, 1 deletion
unittests/test_converters.py
with
32 additions
and
1 deletion
src/caoscrawler/default_transformers.yml
+
3
−
0
View file @
9713d134
...
...
@@ -6,3 +6,6 @@ submatch:
split
:
package
:
caoscrawler.transformer_functions
function
:
split
replace
:
package
:
caoscrawler.transformer_functions
function
:
split
This diff is collapsed.
Click to expand it.
src/caoscrawler/transformer_functions.py
+
11
−
0
View file @
9713d134
...
...
@@ -50,3 +50,14 @@ def split(in_value: Any, in_parameters: dict):
if
not
isinstance
(
in_value
,
str
):
raise
RuntimeError
(
"
must be string
"
)
return
in_value
.
split
(
in_parameters
[
'
marker
'
])
def
replace
(
in_value
:
Any
,
in_parameters
:
dict
):
"""
calls the string
'
replace
'
function on the first argument and uses the value of the keys
'
remove
'
and
'
insert
'
stored in the second argument
"""
if
"
remove
"
not
in
in_parameters
or
"
insert
"
not
in
in_parameters
:
raise
RuntimeError
(
"
Mandatory parameter missing.
"
)
if
not
isinstance
(
in_value
,
str
):
raise
RuntimeError
(
"
must be string
"
)
return
in_value
.
replace
(
in_parameters
[
'
remove
'
],
in_parameters
[
'
insert
'
])
This diff is collapsed.
Click to expand it.
unittests/test_converters.py
+
18
−
1
View file @
9713d134
...
...
@@ -51,7 +51,7 @@ from caoscrawler.structure_elements import (BooleanElement, DictElement,
Directory
,
File
,
FloatElement
,
IntegerElement
,
ListElement
,
TextElement
)
from
caoscrawler.transformer_functions
import
split
from
caoscrawler.transformer_functions
import
replace
,
split
UNITTESTDIR
=
Path
(
__file__
).
parent
...
...
@@ -400,6 +400,23 @@ def test_apply_transformers(converter_registry):
assert
values
[
'
a
'
]
==
[
"
a
"
,
"
b
"
,
"
c
"
]
def
test_apply_replace
(
converter_registry
):
cfood_def
=
{
"
type
"
:
'
ListElement
'
,
"
match_name
"
:
"
.*
"
,
'
transform
'
:
{
'
test
'
:
{
'
in
'
:
'
$a
'
,
'
out
'
:
'
$b
'
,
'
functions
'
:
[{
'
replace
'
:
{
'
insert
'
:
'
:
'
,
"
remove
"
:
"
_
"
}}]}}}
values
=
GeneralStore
()
values
[
"
a
"
]
=
"
16_45
"
# transformer_functions = create_transformer_registry(crawler_definition)
transformer_functions
=
{
"
replace
"
:
replace
}
conv
=
ListElementConverter
(
definition
=
cfood_def
,
name
=
'
test
'
,
converter_registry
=
converter_registry
)
conv
.
apply_transformers
(
values
,
transformer_functions
)
assert
values
[
'
b
'
]
==
"
16:45
"
def
test_filter_children_of_directory
(
converter_registry
,
capsys
):
"""
Verify that children (i.e., files) in a directory are filtered or sorted correctly.
"""
test_dir
=
Directory
(
"
examples_filter_children
"
,
UNITTESTDIR
/
...
...
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