-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent accidental renaming when using with_suffix #1192
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
from tempfile import TemporaryDirectory | ||
|
||
import numpy as np | ||
import pytest | ||
from pathlib import Path | ||
|
||
from lhotse import ( | ||
LilcomFilesWriter, | ||
NumpyFilesWriter, | ||
NumpyHdf5Writer, | ||
LilcomHdf5Writer, | ||
ChunkedLilcomHdf5Writer, | ||
LilcomChunkyWriter, | ||
) | ||
from lhotse.utils import is_module_available | ||
|
||
|
||
@pytest.mark.parametrize( | ||
["writer_type", "ext"], | ||
[ | ||
(LilcomFilesWriter, '.llc'), | ||
(NumpyFilesWriter, '.npy'), | ||
], | ||
) | ||
def test_writer_saved_file(writer_type, ext): | ||
# Generate small random numbers that are nicely compressed with lilcom | ||
arr = np.log(np.random.uniform(size=(11, 80)).astype(np.float32) / 100) | ||
|
||
with TemporaryDirectory() as d, writer_type(d) as writer: | ||
|
||
#testing that words after . is not replace | ||
input_key = "random0.3_vad.alpha" | ||
key = writer.write(input_key, arr) | ||
assert key == f"ran/{input_key}{ext}" | ||
|
||
#Testing when end with extension it is not added again | ||
input_key = f"temp0.2.alpha{ext}" | ||
key = writer.write(input_key, arr) | ||
assert key == f"tem/{input_key}" | ||
|
||
@pytest.mark.parametrize( | ||
["writer_type", "ext"], | ||
[ | ||
pytest.param( | ||
NumpyHdf5Writer, | ||
".h5", | ||
marks=pytest.mark.skipif( | ||
not is_module_available("h5py"), | ||
reason="Requires h5py to run HDF5 tests.", | ||
), | ||
), | ||
pytest.param( | ||
LilcomHdf5Writer, | ||
".h5", | ||
marks=pytest.mark.skipif( | ||
not is_module_available("h5py"), | ||
reason="Requires h5py to run HDF5 tests.", | ||
), | ||
), | ||
pytest.param( | ||
ChunkedLilcomHdf5Writer, | ||
".h5", | ||
marks=pytest.mark.skipif( | ||
not is_module_available("h5py"), | ||
reason="Requires h5py to run HDF5 tests.", | ||
), | ||
), | ||
(LilcomChunkyWriter, ".lca") | ||
], | ||
) | ||
def test_chunk_writer_saved_file(writer_type, ext): | ||
|
||
with TemporaryDirectory() as d: | ||
|
||
#testing that words after . is not replace | ||
filename = "random0.3_vad.alpha" | ||
with writer_type(f"{d}/{filename}") as writer: | ||
assert writer.storage_path_ == Path(f"{d}/{filename}{ext}") | ||
|
||
#Testing when end with extension it is not added again | ||
filename = f"random0.3_vad.alpha{ext}" | ||
with writer_type(f"{d}/{filename}") as writer: | ||
assert writer.storage_path_ == Path(f"{d}/{filename}") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the if/else needed here? (Same for all below changes)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The if/else is to prevent adding of suffix if
p
contains the suffix for some reason say "test.llc". So it will not become "test.llc.llc".Which is the expected behavior mentioned here
https://github.com/lhotse-speech/lhotse/blob/master/lhotse/features/io.py#L443