-
Notifications
You must be signed in to change notification settings - Fork 1
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
MoveOperation bugfix for CLI overrides #36
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f61723e
moveoperation: print operation on failure
gtronset 74bda74
Move setting of operation to import_begin
gtronset b29916d
Fix test error log
gtronset 667d652
Refactor and add tests
gtronset 401c7d5
Rename function
gtronset 0305204
Remove log
gtronset 181a617
Add docstring
gtronset 407f3b9
Update README
gtronset cd43965
Update syntax for pylint override
gtronset File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ beets/ | |
*.egg-info/ | ||
.vscode/ | ||
.DS_Store | ||
*.pyc | ||
*.swp |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -40,7 +40,9 @@ def capture_log(logger="beets"): | |
|
||
|
||
class FiletoteTestCase(_common.TestCase): | ||
# pylint: disable=too-many-instance-attributes, protected-access | ||
# pylint: disable=too-many-instance-attributes | ||
# pylint: disable=protected-access | ||
# pylint: disable=logging-fstring-interpolation | ||
""" | ||
Provides common setup and teardown, a convenience method for exercising the | ||
plugin/importer, tools to setup a library, a directory containing files | ||
|
@@ -68,7 +70,7 @@ def setUp(self): | |
# Install the DummyIO to capture anything directed to stdout | ||
self.in_out.install() | ||
|
||
def _run_importer(self): | ||
def _run_importer(self, operation_option=None): | ||
""" | ||
Create an instance of the plugin, run the importer, and | ||
remove/unregister the plugin instance so a new instance can | ||
|
@@ -81,6 +83,13 @@ def _run_importer(self): | |
# Create an instance of the plugin | ||
plugins.find_plugins() | ||
|
||
if operation_option == "copy": | ||
config["import"]["copy"] = True | ||
config["import"]["move"] = False | ||
elif operation_option == "move": | ||
config["import"]["copy"] = False | ||
config["import"]["move"] = True | ||
|
||
# Exercise | ||
# Run the importer | ||
self.importer.run() | ||
|
@@ -305,10 +314,10 @@ def _list_files(self, startpath): | |
for root, _dirs, files in os.walk(path): | ||
level = root.replace(path, "").count(os.sep) | ||
indent = self._indenter(level) | ||
log.debug("%s%s/", indent, os.path.basename(root)) | ||
log.debug(f"{indent}{os.path.basename(root)}/") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With how the logger is passed around, |
||
subindent = self._indenter(level + 1) | ||
for filename in files: | ||
log.debug("%s%s", subindent, filename) | ||
log.debug(f"{subindent}{filename}") | ||
|
||
def assert_in_lib_dir(self, *segments): | ||
""" | ||
|
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,132 @@ | ||
# pylint: disable=duplicate-code | ||
|
||
import os | ||
|
||
import beets | ||
from beets import config | ||
|
||
from tests.helper import FiletoteTestCase | ||
|
||
|
||
class FiletoteMoveOperation(FiletoteTestCase): | ||
""" | ||
Tests to check handling of the operation (copy, move, etc.) can be | ||
overridden by the CLI. | ||
""" | ||
|
||
def setUp(self): | ||
"""Provides shared setup for tests.""" | ||
super().setUp() | ||
|
||
self._set_import_dir() | ||
self.album_path = os.path.join(self.import_dir, b"the_album") | ||
self.rsrc_mp3 = b"full.mp3" | ||
os.makedirs(self.album_path) | ||
|
||
config["filetote"]["extensions"] = ".file" | ||
|
||
def test_import_config_copy_false_import_op_copy(self): | ||
"""Tests that when config does not have an operation set, that | ||
providing it as `--copy` in the CLI correctly overrides.""" | ||
|
||
self._setup_import_session(copy=False, autotag=False) | ||
|
||
self._create_file( | ||
self.album_path, beets.util.bytestring_path("\xe4rtifact.file") | ||
) | ||
medium = self._create_medium( | ||
os.path.join(self.album_path, b"track_1.mp3"), self.rsrc_mp3 | ||
) | ||
self.import_media = [medium] | ||
|
||
self._run_importer(operation_option="copy") | ||
|
||
self.assert_in_import_dir( | ||
b"the_album", | ||
beets.util.bytestring_path("\xe4rtifact.file"), | ||
) | ||
|
||
self.assert_in_lib_dir( | ||
b"Tag Artist", | ||
b"Tag Album", | ||
beets.util.bytestring_path("\xe4rtifact.file"), | ||
) | ||
|
||
def test_import_config_copy_false_import_op_move(self): | ||
"""Tests that when config does not have an operation set, that | ||
providing it as `--move` in the CLI correctly overrides.""" | ||
self._setup_import_session(copy=False, autotag=False) | ||
|
||
self._create_file( | ||
self.album_path, beets.util.bytestring_path("\xe4rtifact.file") | ||
) | ||
medium = self._create_medium( | ||
os.path.join(self.album_path, b"track_1.mp3"), self.rsrc_mp3 | ||
) | ||
self.import_media = [medium] | ||
|
||
self._run_importer(operation_option="move") | ||
|
||
self.assert_not_in_import_dir( | ||
b"the_album", | ||
beets.util.bytestring_path("\xe4rtifact.file"), | ||
) | ||
|
||
self.assert_in_lib_dir( | ||
b"Tag Artist", | ||
b"Tag Album", | ||
beets.util.bytestring_path("\xe4rtifact.file"), | ||
) | ||
|
||
def test_import_config_copy_true_import_op_move(self): | ||
"""Tests that when config operation is set to `copy`, that providing | ||
`--move` in the CLI correctly overrides.""" | ||
|
||
self._setup_import_session(copy=True, autotag=False) | ||
|
||
self._create_file( | ||
self.album_path, beets.util.bytestring_path("\xe4rtifact.file") | ||
) | ||
medium = self._create_medium( | ||
os.path.join(self.album_path, b"track_1.mp3"), self.rsrc_mp3 | ||
) | ||
self.import_media = [medium] | ||
|
||
self._run_importer(operation_option="move") | ||
|
||
self.assert_not_in_import_dir( | ||
b"the_album", | ||
beets.util.bytestring_path("\xe4rtifact.file"), | ||
) | ||
|
||
self.assert_in_lib_dir( | ||
b"Tag Artist", | ||
b"Tag Album", | ||
beets.util.bytestring_path("\xe4rtifact.file"), | ||
) | ||
|
||
def test_import_config_move_true_import_op_copy(self): | ||
"""Tests that when config operation is set to `move`, that providing | ||
`--copy` in the CLI correctly overrides.""" | ||
self._setup_import_session(move=True, autotag=False) | ||
|
||
self._create_file( | ||
self.album_path, beets.util.bytestring_path("\xe4rtifact.file") | ||
) | ||
medium = self._create_medium( | ||
os.path.join(self.album_path, b"track_1.mp3"), self.rsrc_mp3 | ||
) | ||
self.import_media = [medium] | ||
|
||
self._run_importer(operation_option="copy") | ||
|
||
self.assert_in_import_dir( | ||
b"the_album", | ||
beets.util.bytestring_path("\xe4rtifact.file"), | ||
) | ||
|
||
self.assert_in_lib_dir( | ||
b"Tag Artist", | ||
b"Tag Album", | ||
beets.util.bytestring_path("\xe4rtifact.file"), | ||
) |
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.
This was a legacy
TODO
that is now resolved.The
beets.config
module provides the current config when referenced and not just the values inconfig.yml
. Fixing when theself.operation
is obtained deprecates this TODO.