Skip to content

Commit

Permalink
Merge pull request #2131 from AllenInstitute/bugfix/create_ecephys_up…
Browse files Browse the repository at this point in the history
…load_dir

tests for production mkdir error and fixes
  • Loading branch information
djkapner authored May 21, 2021
2 parents 96fb304 + 5be964b commit b29058f
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
All notable changes to this project will be documented in this file.


## [2.11.2] = 2021-05-21
- Fixed mkdir error for non-existing ecephys upload directory

## [2.11.1] = 2021-05-20
- Refactored the schema for the ecephys copy utility to avoid raising an error when a previous output file already exists.

Expand Down
2 changes: 1 addition & 1 deletion allensdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#
import logging

__version__ = '2.11.1'
__version__ = '2.11.2'


try:
Expand Down
13 changes: 7 additions & 6 deletions allensdk/brain_observatory/ecephys/copy_utility/_schemas.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import hashlib

from argschema import ArgSchema
from argschema.fields import (
LogLevel, String, Int, Nested, Boolean, List, InputFile, OutputFile)
LogLevel, String, Int, Nested, Boolean, List, InputFile)
from argschema.schemas import DefaultSchema


Expand All @@ -18,10 +17,12 @@ class FileExists(InputFile):


class FileToCopy(DefaultSchema):
source = InputFile(required=True, description='copy from here')
destination = OutputFile(required=True,
description='copy to here (full path, not just '
'directory!)')
source = InputFile(
required=True,
description='copy from here')
destination = String(
required=True,
description='copy to here (full path, not just directory!)')
key = String(required=True,
description='will be passed through to outputs, allowing a '
'name or kind to be associated with this file')
Expand Down
41 changes: 40 additions & 1 deletion allensdk/test/brain_observatory/ecephys/test_copy_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,46 @@

import allensdk.brain_observatory.ecephys.copy_utility.__main__ as cu
from allensdk.brain_observatory.ecephys.copy_utility._schemas import (
SessionUploadInputSchema, SessionUploadOutputSchema)
SessionUploadInputSchema, SessionUploadOutputSchema)


@pytest.mark.parametrize("already_exists", [True, False])
def test_dst_dir_exists(already_exists, tmp_path, monkeypatch):
dst_dir = tmp_path / "new_directory"
src_file = tmp_path / "source.txt"
src_file.touch()

if already_exists:
dst_dir.mkdir()
dst_file = dst_dir / "destination.txt"
outj_path = tmp_path / "output.json"

args = {
"files": [
{
"source": str(src_file),
"destination": str(dst_file),
"key": "something"}],
"output_json": str(outj_path)}

parser = argschema.ArgSchemaParser(
args,
schema_type=SessionUploadInputSchema,
output_schema_type=SessionUploadOutputSchema,
args=[]
)

def mock_copy_file(source, dest, use_rsync, make_parent_dirs, chmod=None):
parent = Path(dest).parent
if make_parent_dirs & (not parent.exists()):
parent.mkdir()
shutil.copy(source, dest)

monkeypatch.setattr(cu, "copy_file_entry", mock_copy_file)
output = cu.main(**parser.args)
parser.output(output, indent=2)
assert outj_path.exists()
assert Path(args["files"][0]["destination"]).exists()


def test_hash_file(tmpdir_factory):
Expand Down
7 changes: 6 additions & 1 deletion doc_template/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,12 @@ The Allen SDK provides Python code for accessing experimental metadata along wit
See the `mouse connectivity section <connectivity.html>`_ for more details.


What's New - 2.11.0
What's New - 2.11.2
-----------------------------------------------------------------------
- Fixed mkdir error for non-existing ecephys upload directory


What's New - 2.11.1
-----------------------------------------------------------------------
- Refactored the schema for the Ecephys copy utility to avoid raising an error when a previous output file already exists.

Expand Down

0 comments on commit b29058f

Please sign in to comment.