Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lvcnrpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
waveforms
lvcnrpy
Commits
acc4e36f
Commit
acc4e36f
authored
8 years ago
by
Edward Fauchon-Jones
Browse files
Options
Downloads
Patches
Plain Diff
Add `lvcnrcheck` test helper module
parent
43e6765f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lvcnrpy/test/__init__.py
+0
-0
0 additions, 0 deletions
lvcnrpy/test/__init__.py
lvcnrpy/test/test_lvcnrcheck_helper.py
+88
-0
88 additions, 0 deletions
lvcnrpy/test/test_lvcnrcheck_helper.py
with
88 additions
and
0 deletions
lvcnrpy/test/__init__.py
0 → 100644
+
0
−
0
View file @
acc4e36f
This diff is collapsed.
Click to expand it.
lvcnrpy/test/test_lvcnrcheck_helper.py
0 → 100644
+
88
−
0
View file @
acc4e36f
# Copyright (C) 2016 Edward Fauchon-Jones
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from
subprocess
import
Popen
,
PIPE
,
STDOUT
from
tempfile
import
NamedTemporaryFile
import
os
from
lvcnrpy.format.format
import
format1
,
format2
,
format3
from
lvcnrpy.format.specs
import
Spec
,
DatasetSpec
import
h5py
as
h5
from
collections
import
OrderedDict
import
numpy
as
np
def
lvcnrcheck
(
args
):
"""
Software API adapter for `lvcnrcheck`
API to `lvcnrcheck` since `lvcnrcheck` only provides a CLI.
Parameters
----------
args: list
List of command line argument to call `lvcnrcheck` with. Typically this
should end with a path to a HDF5 file to validate against the LVCNR
Wavform Reopsitory format specification.
Returns
-------
output: str
Standard output that would be recived from calling `lvcnrcheck` through
the CLI interface with `h5Path`.
"""
pipe
=
Popen
([
'
lvcnrcheck
'
]
+
args
,
stdout
=
PIPE
,
stderr
=
STDOUT
)
output
=
pipe
.
communicate
()[
0
]
return
output
def
getFormat1HDF5
():
"""
Create a temporary HDF5 file that is a valid format 1 file.
Returns
-------
file: NamedTemporaryFile
`NamedTemporaryFile` object that is initialized as a HDF5 file that is
a valid format 1 file.
"""
f
=
NamedTemporaryFile
()
h5f
=
h5
.
File
(
f
.
name
,
'
w
'
)
def
createLeaves
(
nodes
):
for
nodeKey
,
node
in
nodes
.
items
():
if
isinstance
(
node
,
OrderedDict
):
createLeaves
(
node
)
elif
isinstance
(
node
(),
Spec
):
if
node
.
dtype
==
h5
.
Group
:
h5f
.
create_group
(
node
.
name
)
continue
elif
isinstance
(
node
(),
DatasetSpec
):
el
=
[
float
(
i
)
for
i
in
range
(
node
.
componentCount
)]
data
=
np
.
array
([
el
for
i
in
range
(
10
)])
h5f
.
create_dataset
(
node
.
name
,
data
=
data
)
continue
elif
node
.
dtype
==
int
:
val
=
node
.
values
[
0
]
if
node
.
values
is
not
None
else
1
elif
node
.
dtype
==
float
:
val
=
node
.
values
[
0
]
if
node
.
values
is
not
None
else
1.0
elif
node
.
dtype
==
basestring
:
val
=
node
.
values
[
0
]
if
node
.
values
is
not
None
else
"
1.0
"
h5f
.
attrs
[
node
.
name
]
=
val
createLeaves
(
format1
)
createLeaves
(
format2
)
createLeaves
(
format3
)
h5f
.
close
()
return
f
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