Added --regex query option, closes #433

This commit is contained in:
Rhet Turnbull
2021-04-20 20:17:44 -07:00
parent 7c4b28a35c
commit 44966c6736
20 changed files with 196 additions and 14 deletions

View File

@@ -5993,3 +5993,111 @@ def test_query_min_size_error():
)
assert result.exit_code != 0
def test_query_regex_1():
""" test query --regex against title """
import json
import os
import os.path
import osxphotos
from osxphotos.cli import query
runner = CliRunner()
cwd = os.getcwd()
result = runner.invoke(
query,
[
"--json",
"--db",
os.path.join(cwd, PHOTOS_DB_15_7),
"--regex",
"I found",
"{title}",
],
)
assert result.exit_code == 0
json_got = json.loads(result.output)
assert len(json_got) == 1
def test_query_regex_2():
""" test query --regex with no match"""
import json
import os
import os.path
import osxphotos
from osxphotos.cli import query
runner = CliRunner()
cwd = os.getcwd()
result = runner.invoke(
query,
[
"--json",
"--db",
os.path.join(cwd, PHOTOS_DB_15_7),
"--regex",
"{title}",
"i Found",
],
)
assert result.exit_code == 0
json_got = json.loads(result.output)
assert len(json_got) == 0
def test_query_regex_3():
""" test query --regex with --ignore-case """
import json
import os
import os.path
import osxphotos
from osxphotos.cli import query
runner = CliRunner()
cwd = os.getcwd()
result = runner.invoke(
query,
[
"--json",
"--db",
os.path.join(cwd, PHOTOS_DB_15_7),
"--regex",
"i Found",
"{title}",
"--ignore-case",
],
)
assert result.exit_code == 0
json_got = json.loads(result.output)
assert len(json_got) == 1
def test_query_regex_4():
""" test query --regex against album """
import json
import os
import os.path
import osxphotos
from osxphotos.cli import query
runner = CliRunner()
cwd = os.getcwd()
result = runner.invoke(
query,
[
"--json",
"--db",
os.path.join(cwd, PHOTOS_DB_15_7),
"--regex",
"^Test",
"{album}",
],
)
assert result.exit_code == 0
json_got = json.loads(result.output)
assert len(json_got) == 2