aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_postprocessor.py19
-rw-r--r--test/test_results.py2
-rw-r--r--test/test_util.py24
3 files changed, 41 insertions, 4 deletions
diff --git a/test/test_postprocessor.py b/test/test_postprocessor.py
index 6bf887c..00c17b2 100644
--- a/test/test_postprocessor.py
+++ b/test/test_postprocessor.py
@@ -30,13 +30,17 @@ class MockPostprocessorModule(Mock):
class FakeJob():
- def __init__(self):
- self.extractor = extractor.find("test:")
- self.pathfmt = util.PathFormat(self.extractor)
+ def __init__(self, extr=extractor.find("test:")):
+ self.extractor = extr
+ self.pathfmt = util.PathFormat(extr)
self.out = output.NullOutput()
self.get_logger = logging.getLogger
self.hooks = collections.defaultdict(list)
+ def register_hooks(self, hooks, options):
+ for hook, callback in hooks.items():
+ self.hooks[hook].append(callback)
+
class TestPostprocessorModule(unittest.TestCase):
@@ -239,6 +243,15 @@ class MetadataTest(BasePostprocessorTest):
self._trigger()
self.assertEqual(self._output(m), "foo\nbar\nbaz\n")
+ def test_metadata_tags_dict(self):
+ self._create(
+ {"mode": "tags"},
+ {"tags": {"g": ["foobar1", "foobar2"], "m": ["foobarbaz"]}},
+ )
+ with patch("builtins.open", mock_open()) as m:
+ self._trigger()
+ self.assertEqual(self._output(m), "foobar1\nfoobar2\nfoobarbaz\n")
+
def test_metadata_custom(self):
def test(pp_info):
pp = self._create(pp_info, {"foo": "bar"})
diff --git a/test/test_results.py b/test/test_results.py
index bf2496b..5b22ecd 100644
--- a/test/test_results.py
+++ b/test/test_results.py
@@ -312,7 +312,7 @@ def setup_test_config():
config.set(("extractor", "mangoxo") , "password", "5zbQF10_5u25259Ma")
for category in ("danbooru", "instagram", "twitter", "subscribestar",
- "e621", "inkbunny", "tapas", "pillowfort"):
+ "e621", "inkbunny", "tapas", "pillowfort", "mangadex"):
config.set(("extractor", category), "username", None)
config.set(("extractor", "mastodon.social"), "access-token",
diff --git a/test/test_util.py b/test/test_util.py
index e2f5084..d90d5ad 100644
--- a/test/test_util.py
+++ b/test/test_util.py
@@ -493,6 +493,30 @@ class TestOther(unittest.TestCase):
def test_noop(self):
self.assertEqual(util.noop(), None)
+ def test_compile_expression(self):
+ expr = util.compile_expression("1 + 2 * 3")
+ self.assertEqual(expr(), 7)
+ self.assertEqual(expr({"a": 1, "b": 2, "c": 3}), 7)
+ self.assertEqual(expr({"a": 9, "b": 9, "c": 9}), 7)
+
+ expr = util.compile_expression("a + b * c")
+ self.assertEqual(expr({"a": 1, "b": 2, "c": 3}), 7)
+ self.assertEqual(expr({"a": 9, "b": 9, "c": 9}), 90)
+
+ with self.assertRaises(NameError):
+ expr()
+ with self.assertRaises(NameError):
+ expr({"a": 2})
+
+ with self.assertRaises(SyntaxError):
+ util.compile_expression("")
+ with self.assertRaises(SyntaxError):
+ util.compile_expression("x++")
+
+ expr = util.compile_expression("1 and abort()")
+ with self.assertRaises(exception.StopExtraction):
+ expr()
+
def test_generate_token(self):
tokens = set()
for _ in range(100):