Feature add query command (#970)
* Added query_command and example * Refactored QUERY_OPTIONS, added query_command, refactored verbose, #930, #931 * Added query options to debug-dump, #966 * Refactored query, #602 * Added precedence test for --load-config * Refactored handling of query options * Refactored export_photo * Removed extraneous print * Updated API_README * Updated examples
This commit is contained in:
@@ -3616,7 +3616,7 @@ def test_export_sidecar_invalid():
|
||||
],
|
||||
)
|
||||
assert result.exit_code != 0
|
||||
assert "Cannot use --sidecar json with --sidecar exiftool" in result.output
|
||||
assert "cannot use --sidecar json with --sidecar exiftool" in result.output
|
||||
|
||||
|
||||
def test_export_live():
|
||||
@@ -4242,7 +4242,9 @@ def test_places():
|
||||
cwd = os.getcwd()
|
||||
# pylint: disable=not-context-manager
|
||||
with runner.isolated_filesystem():
|
||||
result = runner.invoke(places, [os.path.join(cwd, PLACES_PHOTOS_DB), "--json"])
|
||||
result = runner.invoke(
|
||||
places, ["--db", os.path.join(cwd, PLACES_PHOTOS_DB), "--json"]
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
json_got = json.loads(result.output)
|
||||
assert json_got == json.loads(CLI_PLACES_JSON)
|
||||
@@ -4257,7 +4259,13 @@ def test_place_13():
|
||||
with runner.isolated_filesystem():
|
||||
result = runner.invoke(
|
||||
query,
|
||||
[os.path.join(cwd, PLACES_PHOTOS_DB_13), "--json", "--place", "Adelaide"],
|
||||
[
|
||||
"--db",
|
||||
os.path.join(cwd, PLACES_PHOTOS_DB_13),
|
||||
"--json",
|
||||
"--place",
|
||||
"Adelaide",
|
||||
],
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
json_got = json.loads(result.output)
|
||||
@@ -4274,7 +4282,8 @@ def test_no_place_13():
|
||||
# pylint: disable=not-context-manager
|
||||
with runner.isolated_filesystem():
|
||||
result = runner.invoke(
|
||||
query, [os.path.join(cwd, PLACES_PHOTOS_DB_13), "--json", "--no-place"]
|
||||
query,
|
||||
["--db", os.path.join(cwd, PLACES_PHOTOS_DB_13), "--json", "--no-place"],
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
json_got = json.loads(result.output)
|
||||
@@ -4292,7 +4301,13 @@ def test_place_15_1():
|
||||
with runner.isolated_filesystem():
|
||||
result = runner.invoke(
|
||||
query,
|
||||
[os.path.join(cwd, PLACES_PHOTOS_DB), "--json", "--place", "Washington"],
|
||||
[
|
||||
"--db",
|
||||
os.path.join(cwd, PLACES_PHOTOS_DB),
|
||||
"--json",
|
||||
"--place",
|
||||
"Washington",
|
||||
],
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
json_got = json.loads(result.output)
|
||||
@@ -4310,7 +4325,13 @@ def test_place_15_2():
|
||||
with runner.isolated_filesystem():
|
||||
result = runner.invoke(
|
||||
query,
|
||||
[os.path.join(cwd, PLACES_PHOTOS_DB), "--json", "--place", "United States"],
|
||||
[
|
||||
"--db",
|
||||
os.path.join(cwd, PLACES_PHOTOS_DB),
|
||||
"--json",
|
||||
"--place",
|
||||
"United States",
|
||||
],
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
json_got = json.loads(result.output)
|
||||
@@ -4329,7 +4350,7 @@ def test_no_place_15():
|
||||
# pylint: disable=not-context-manager
|
||||
with runner.isolated_filesystem():
|
||||
result = runner.invoke(
|
||||
query, [os.path.join(cwd, PLACES_PHOTOS_DB), "--json", "--no-place"]
|
||||
query, ["--db", os.path.join(cwd, PLACES_PHOTOS_DB), "--json", "--no-place"]
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
json_got = json.loads(result.output)
|
||||
@@ -4346,7 +4367,14 @@ def test_no_folder_1_15():
|
||||
# pylint: disable=not-context-manager
|
||||
with runner.isolated_filesystem():
|
||||
result = runner.invoke(
|
||||
query, [os.path.join(cwd, PHOTOS_DB_15_7), "--json", "--folder", "Folder1"]
|
||||
query,
|
||||
[
|
||||
"--db",
|
||||
os.path.join(cwd, PHOTOS_DB_15_7),
|
||||
"--json",
|
||||
"--folder",
|
||||
"Folder1",
|
||||
],
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
json_got = json.loads(result.output)
|
||||
@@ -4381,6 +4409,7 @@ def test_no_folder_2_15():
|
||||
result = runner.invoke(
|
||||
query,
|
||||
[
|
||||
"--db",
|
||||
os.path.join(cwd, PHOTOS_DB_15_7),
|
||||
"--json",
|
||||
"--folder",
|
||||
@@ -4408,7 +4437,14 @@ def test_no_folder_1_14():
|
||||
# pylint: disable=not-context-manager
|
||||
with runner.isolated_filesystem():
|
||||
result = runner.invoke(
|
||||
query, [os.path.join(cwd, PHOTOS_DB_14_6), "--json", "--folder", "Folder1"]
|
||||
query,
|
||||
[
|
||||
"--db",
|
||||
os.path.join(cwd, PHOTOS_DB_14_6),
|
||||
"--json",
|
||||
"--folder",
|
||||
"Folder1",
|
||||
],
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
json_got = json.loads(result.output)
|
||||
@@ -5727,19 +5763,6 @@ def test_keywords():
|
||||
assert json_got == KEYWORDS_JSON
|
||||
|
||||
|
||||
# TODO: this fails with result.exit_code == 1 but I think this has to
|
||||
# do with how pytest is invoking the command
|
||||
# def test_albums_str():
|
||||
# """Test osxphotos albums string output """
|
||||
|
||||
# runner = CliRunner()
|
||||
# cwd = os.getcwd()
|
||||
# result = runner.invoke(albums, ["--db", os.path.join(cwd, PHOTOS_DB_15_7), ])
|
||||
# assert result.exit_code == 0
|
||||
|
||||
# assert result.output == ALBUMS_STR
|
||||
|
||||
|
||||
def test_albums_json():
|
||||
"""Test osxphotos albums json output"""
|
||||
|
||||
@@ -6648,6 +6671,57 @@ def test_config_only():
|
||||
assert "config.toml" in files
|
||||
|
||||
|
||||
def test_config_command_line_precedence():
|
||||
"""Test that command line options take precedence over config file"""
|
||||
|
||||
runner = CliRunner()
|
||||
cwd = os.getcwd()
|
||||
|
||||
with runner.isolated_filesystem():
|
||||
# create a config file
|
||||
with open("config.toml", "w") as fd:
|
||||
fd.write("[export]\n")
|
||||
fd.write(
|
||||
"uuid = ["
|
||||
+ ", ".join(f'"{u}"' for u in UUID_EXPECTED_FROM_FILE)
|
||||
+ "]\n"
|
||||
)
|
||||
|
||||
result = runner.invoke(
|
||||
export,
|
||||
[
|
||||
"--db",
|
||||
os.path.join(cwd, CLI_PHOTOS_DB),
|
||||
".",
|
||||
"-V",
|
||||
"--load-config",
|
||||
"config.toml",
|
||||
],
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
for uuid in UUID_EXPECTED_FROM_FILE:
|
||||
assert uuid in result.output
|
||||
|
||||
# now run with a command line option that should override the config file
|
||||
result = runner.invoke(
|
||||
export,
|
||||
[
|
||||
"--db",
|
||||
os.path.join(cwd, CLI_PHOTOS_DB),
|
||||
".",
|
||||
"-V",
|
||||
"--uuid",
|
||||
UUID_NOT_FROM_FILE,
|
||||
"--load-config",
|
||||
"config.toml",
|
||||
],
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
assert UUID_NOT_FROM_FILE in result.output
|
||||
for uuid in UUID_EXPECTED_FROM_FILE:
|
||||
assert uuid not in result.output
|
||||
|
||||
|
||||
def test_export_exportdb():
|
||||
"""test --exportdb"""
|
||||
|
||||
@@ -6657,7 +6731,14 @@ def test_export_exportdb():
|
||||
with runner.isolated_filesystem():
|
||||
result = runner.invoke(
|
||||
export,
|
||||
[os.path.join(cwd, CLI_PHOTOS_DB), ".", "-V", "--exportdb", "export.db"],
|
||||
[
|
||||
"--db",
|
||||
os.path.join(cwd, CLI_PHOTOS_DB),
|
||||
".",
|
||||
"-V",
|
||||
"--exportdb",
|
||||
"export.db",
|
||||
],
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
assert re.search(r"Created export database.*export\.db", result.output)
|
||||
@@ -7921,6 +8002,7 @@ def test_query_function():
|
||||
result = runner.invoke(
|
||||
query,
|
||||
[
|
||||
"--db",
|
||||
os.path.join(cwd, PHOTOS_DB_15_7),
|
||||
"--query-function",
|
||||
f"{tmpdir}/query1.py::query",
|
||||
@@ -7942,6 +8024,7 @@ def test_query_added_after():
|
||||
results = runner.invoke(
|
||||
query,
|
||||
[
|
||||
"--db",
|
||||
os.path.join(cwd, PHOTOS_DB_15_7),
|
||||
"--json",
|
||||
"--added-after",
|
||||
@@ -7962,6 +8045,7 @@ def test_query_added_before():
|
||||
results = runner.invoke(
|
||||
query,
|
||||
[
|
||||
"--db",
|
||||
os.path.join(cwd, PHOTOS_DB_15_7),
|
||||
"--json",
|
||||
"--added-before",
|
||||
|
||||
Reference in New Issue
Block a user