aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_extractor.py9
-rw-r--r--test/test_postprocessor.py12
-rw-r--r--test/test_results.py52
-rw-r--r--test/test_util.py19
-rw-r--r--test/test_ytdl.py14
5 files changed, 70 insertions, 36 deletions
diff --git a/test/test_extractor.py b/test/test_extractor.py
index 6af1226..abf122b 100644
--- a/test/test_extractor.py
+++ b/test/test_extractor.py
@@ -17,7 +17,7 @@ import string
from datetime import datetime, timedelta
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
-from gallery_dl import extractor # noqa E402
+from gallery_dl import extractor, util # noqa E402
from gallery_dl.extractor import mastodon # noqa E402
from gallery_dl.extractor.common import Extractor, Message # noqa E402
from gallery_dl.extractor.directlink import DirectlinkExtractor # noqa E402
@@ -25,7 +25,11 @@ from gallery_dl.extractor.directlink import DirectlinkExtractor # noqa E402
_list_classes = extractor._list_classes
try:
- from test import results
+ RESULTS = os.environ.get("GDL_TEST_RESULTS")
+ if RESULTS:
+ results = util.import_file(RESULTS)
+ else:
+ from test import results
except ImportError:
results = None
@@ -109,6 +113,7 @@ class TestExtractorModule(unittest.TestCase):
print("Skipping '{}' category checks".format(cat))
continue
raise
+ self.assertTrue(extr, url)
self.assertEqual(extr.category, cat, url)
self.assertEqual(extr.subcategory, sub, url)
self.assertEqual(extr.basecategory, base, url)
diff --git a/test/test_postprocessor.py b/test/test_postprocessor.py
index d509052..3e6d1df 100644
--- a/test/test_postprocessor.py
+++ b/test/test_postprocessor.py
@@ -440,6 +440,18 @@ class MetadataTest(BasePostprocessorTest):
path = self.pathfmt.realdirectory + "metadata/file.json"
m.assert_called_once_with(path, "w", encoding="utf-8")
+ def test_metadata_directory_format(self):
+ self._create(
+ {"directory": ["..", "json", "\fE str(id // 500 * 500 + 500)"]},
+ {"id": 12345},
+ )
+
+ with patch("builtins.open", mock_open()) as m:
+ self._trigger()
+
+ path = self.pathfmt.realdirectory + "../json/12500/file.ext.json"
+ m.assert_called_once_with(path, "w", encoding="utf-8")
+
def test_metadata_filename(self):
self._create({
"filename" : "{category}_{filename}_/meta/\n\r.data",
diff --git a/test/test_results.py b/test/test_results.py
index ab3668e..e2c7ca2 100644
--- a/test/test_results.py
+++ b/test/test_results.py
@@ -20,7 +20,13 @@ import collections
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from gallery_dl import \
extractor, util, job, config, exception, formatter # noqa E402
-from test import results # noqa E402
+
+
+RESULTS = os.environ.get("GDL_TEST_RESULTS")
+if RESULTS:
+ results = util.import_file(RESULTS)
+else:
+ from test import results
# temporary issues, etc.
@@ -86,38 +92,34 @@ class TestExtractorResults(unittest.TestCase):
def _run_test(self, result):
result.pop("#comment", None)
- only_matching = (len(result) <= 3)
+ auth = result.pop("#auth", None)
+
+ extractor.find(result["#url"])
+ extr = result["#class"].from_url(result["#url"])
+ if not extr:
+ raise exception.NoExtractorError()
+ if len(result) <= 3:
+ return # only matching
- auth = result.get("#auth")
if auth is None:
auth = (result["#category"][1] in AUTH)
elif not auth:
+ # auth explicitly disabled
for key in AUTH_CONFIG:
config.set((), key, None)
- if auth:
- extr = result["#class"].from_url(result["#url"])
- if not any(extr.config(key) for key in AUTH_CONFIG):
- self._skipped.append((result["#url"], "no auth"))
- only_matching = True
+ if auth and not any(extr.config(key) for key in AUTH_CONFIG):
+ return self._skipped.append((result["#url"], "no auth"))
- if only_matching:
- content = False
- else:
- if "#options" in result:
- for key, value in result["#options"].items():
- key = key.split(".")
- config.set(key[:-1], key[-1], value)
- if "#range" in result:
- config.set((), "image-range" , result["#range"])
- config.set((), "chapter-range", result["#range"])
- content = ("#sha1_content" in result)
-
- tjob = ResultJob(result["#url"], content=content)
- self.assertEqual(result["#class"], tjob.extractor.__class__, "#class")
-
- if only_matching:
- return
+ if "#options" in result:
+ for key, value in result["#options"].items():
+ key = key.split(".")
+ config.set(key[:-1], key[-1], value)
+ if "#range" in result:
+ config.set((), "image-range" , result["#range"])
+ config.set((), "chapter-range", result["#range"])
+
+ tjob = ResultJob(extr, content=("#sha1_content" in result))
if "#exception" in result:
with self.assertRaises(result["#exception"], msg="#exception"):
diff --git a/test/test_util.py b/test/test_util.py
index 35e7247..4622c28 100644
--- a/test/test_util.py
+++ b/test/test_util.py
@@ -134,19 +134,18 @@ class TestPredicate(unittest.TestCase):
with self.assertRaises(SyntaxError):
util.FilterPredicate("(")
- with self.assertRaises(exception.FilterError):
- util.FilterPredicate("a > 1")(url, {"a": None})
-
- with self.assertRaises(exception.FilterError):
- util.FilterPredicate("b > 1")(url, {"a": 2})
+ self.assertFalse(
+ util.FilterPredicate("a > 1")(url, {"a": None}))
+ self.assertFalse(
+ util.FilterPredicate("b > 1")(url, {"a": 2}))
pred = util.FilterPredicate(["a < 3", "b < 4", "c < 5"])
self.assertTrue(pred(url, {"a": 2, "b": 3, "c": 4}))
self.assertFalse(pred(url, {"a": 3, "b": 3, "c": 4}))
self.assertFalse(pred(url, {"a": 2, "b": 4, "c": 4}))
self.assertFalse(pred(url, {"a": 2, "b": 3, "c": 5}))
- with self.assertRaises(exception.FilterError):
- pred(url, {"a": 2})
+
+ self.assertFalse(pred(url, {"a": 2}))
def test_build_predicate(self):
pred = util.build_predicate([])
@@ -445,6 +444,7 @@ class TestOther(unittest.TestCase):
self.assertEqual(expr({"a": 1, "b": 2, "c": 3}), 7)
self.assertEqual(expr({"a": 9, "b": 9, "c": 9}), 90)
+ expr = util.compile_expression_raw("a + b * c")
with self.assertRaises(NameError):
expr()
with self.assertRaises(NameError):
@@ -755,8 +755,9 @@ def hash(value):
self.assertLess(obj, "foo")
self.assertLessEqual(obj, None)
- self.assertFalse(obj == obj)
- self.assertTrue(obj != obj)
+ self.assertTrue(obj == obj)
+ self.assertFalse(obj == 0)
+ self.assertFalse(obj != obj)
self.assertGreater(123, obj)
self.assertGreaterEqual(1.23, obj)
diff --git a/test/test_ytdl.py b/test/test_ytdl.py
index 878ac85..fd2e40a 100644
--- a/test/test_ytdl.py
+++ b/test/test_ytdl.py
@@ -294,6 +294,20 @@ class Test_CommandlineArguments_YtDlp(Test_CommandlineArguments):
self._(["--geo-bypass-ip-block", "198.51.100.14/24"],
"geo_bypass", "198.51.100.14/24")
+ def test_cookiesfrombrowser(self):
+ self._(["--cookies-from-browser", "firefox"],
+ "cookiesfrombrowser", ("firefox", None, None, None))
+ self._(["--cookies-from-browser", "firefox:profile"],
+ "cookiesfrombrowser", ("firefox", "profile", None, None))
+ self._(["--cookies-from-browser", "firefox+keyring"],
+ "cookiesfrombrowser", ("firefox", None, "KEYRING", None))
+ self._(["--cookies-from-browser", "firefox::container"],
+ "cookiesfrombrowser", ("firefox", None, None, "container"))
+ self._(["--cookies-from-browser",
+ "firefox+keyring:profile::container"],
+ "cookiesfrombrowser",
+ ("firefox", "profile", "KEYRING", "container"))
+
if __name__ == "__main__":
unittest.main(warnings="ignore")