diff options
| author | 2022-04-09 00:15:19 -0400 | |
|---|---|---|
| committer | 2022-04-09 00:15:19 -0400 | |
| commit | 2fe1dfed848fc26b7419e3bfe91a62e686960429 (patch) | |
| tree | 901cb64e2a1748df2bb8c7abc60ff6d72ae4bc27 /test | |
| parent | c2e774d3f5a4499b8beb5a12ab46a0099b16b1e7 (diff) | |
New upstream version 1.21.1.upstream/1.21.1
Diffstat (limited to 'test')
| -rw-r--r-- | test/test_cookies.py | 4 | ||||
| -rw-r--r-- | test/test_formatter.py | 8 | ||||
| -rw-r--r-- | test/test_postprocessor.py | 6 | ||||
| -rw-r--r-- | test/test_util.py | 40 |
4 files changed, 51 insertions, 7 deletions
diff --git a/test/test_cookies.py b/test/test_cookies.py index 0657456..188b54c 100644 --- a/test/test_cookies.py +++ b/test/test_cookies.py @@ -180,14 +180,14 @@ class TestCookieUtils(unittest.TestCase): extr._cookiejar.set("a", "1", expires=now+100) with mock.patch.object(log, "warning") as mw: - self.assertFalse(extr._check_cookies(("a",))) + self.assertTrue(extr._check_cookies(("a",))) self.assertEqual(mw.call_count, 1) self.assertEqual(mw.call_args[0], ( "Cookie '%s' will expire in less than %s hour%s", "a", 1, "")) extr._cookiejar.set("a", "1", expires=now+100+7200) with mock.patch.object(log, "warning") as mw: - self.assertFalse(extr._check_cookies(("a",))) + self.assertTrue(extr._check_cookies(("a",))) self.assertEqual(mw.call_count, 1) self.assertEqual(mw.call_args[0], ( "Cookie '%s' will expire in less than %s hour%s", "a", 3, "s")) diff --git a/test/test_formatter.py b/test/test_formatter.py index 8464b1b..4cce8a3 100644 --- a/test/test_formatter.py +++ b/test/test_formatter.py @@ -232,6 +232,14 @@ class TestFormatter(unittest.TestCase): self._run_test("\fE name * 2 + ' ' + a", "{}{} {}".format( self.kwdict["name"], self.kwdict["name"], self.kwdict["a"])) + @unittest.skipIf(sys.hexversion < 0x3060000, "no fstring support") + def test_fstring(self): + self._run_test("\fF {a}", self.kwdict["a"]) + self._run_test("\fF {name}{name} {a}", "{}{} {}".format( + self.kwdict["name"], self.kwdict["name"], self.kwdict["a"])) + self._run_test("\fF foo-'\"{a.upper()}\"'-bar", + """foo-'"{}"'-bar""".format(self.kwdict["a"].upper())) + def test_module(self): with tempfile.TemporaryDirectory() as tmpdirname: path = os.path.join(tmpdirname, "testmod.py") diff --git a/test/test_postprocessor.py b/test/test_postprocessor.py index 84d2747..e23cfa2 100644 --- a/test/test_postprocessor.py +++ b/test/test_postprocessor.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright 2019-2021 Mike Fährmann +# Copyright 2019-2022 Mike Fährmann # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as @@ -16,7 +16,7 @@ import logging import zipfile import tempfile import collections -from datetime import datetime, timezone as tz +from datetime import datetime sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from gallery_dl import extractor, output, path # noqa E402 @@ -345,7 +345,7 @@ class MtimeTest(BasePostprocessorTest): self.assertEqual(pp.key, "date") def test_mtime_datetime(self): - self._create(None, {"date": datetime(1980, 1, 1, tzinfo=tz.utc)}) + self._create(None, {"date": datetime(1980, 1, 1)}) self._trigger() self.assertEqual(self.pathfmt.kwdict["_mtime"], 315532800) diff --git a/test/test_util.py b/test/test_util.py index ce403a8..3cf3d68 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright 2015-2021 Mike Fährmann +# Copyright 2015-2022 Mike Fährmann # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as @@ -189,6 +189,10 @@ class TestCookiesTxt(unittest.TestCase): [self._cookie("name", "", ".example.org")], ) _assert( + "\tTRUE\t/\tTRUE\t\tname\t", + [self._cookie("name", "", "")], + ) + _assert( "# Netscape HTTP Cookie File\n" "\n" "# default\n" @@ -241,6 +245,8 @@ class TestCookiesTxt(unittest.TestCase): "n4", "" , "www.example.org", False, "/", False), self._cookie( "n5", "v5", "www.example.org", False, "/path", False, 100), + self._cookie( + "n6", "v6", "", False), ], "# Netscape HTTP Cookie File\n" "\n" @@ -313,6 +319,27 @@ class TestOther(unittest.TestCase): self.assertSequenceEqual( list(util.unique_sequence([1, 2, 1, 3, 2, 1])), [1, 2, 1, 3, 2, 1]) + def test_contains(self): + c = [1, "2", 3, 4, "5", "foo"] + self.assertTrue(util.contains(c, 1)) + self.assertTrue(util.contains(c, "foo")) + self.assertTrue(util.contains(c, [1, 3, "5"])) + self.assertTrue(util.contains(c, ["a", "b", "5"])) + self.assertFalse(util.contains(c, "bar")) + self.assertFalse(util.contains(c, [2, 5, "bar"])) + + s = "1 2 3 asd qwe y(+)c f(+)(-) bar" + self.assertTrue(util.contains(s, "y(+)c")) + self.assertTrue(util.contains(s, ["asd", "qwe", "yxc"])) + self.assertTrue(util.contains(s, ["sdf", "dfg", "qwe"])) + self.assertFalse(util.contains(s, "tag1")) + self.assertFalse(util.contains(s, ["tag1", "tag2", "tag3"])) + + s = "1, 2, 3, asd, qwe, y(+)c, f(+)(-), bar" + self.assertTrue(util.contains(s, "y(+)c", ", ")) + self.assertTrue(util.contains(s, ["sdf", "dfg", "qwe"], ", ")) + self.assertFalse(util.contains(s, "tag1", ", ")) + def test_raises(self): func = util.raises(Exception) with self.assertRaises(Exception): @@ -531,7 +558,16 @@ class TestOther(unittest.TestCase): self.assertEqual(f(["a", "b", "c"]), "a, b, c") self.assertEqual(f([1, 2, 3]), "1, 2, 3") - def test_to_timestamp(self, f=util.to_timestamp): + def test_datetime_to_timestamp(self, f=util.datetime_to_timestamp): + self.assertEqual(f(util.EPOCH), 0.0) + self.assertEqual(f(datetime.datetime(2010, 1, 1)), 1262304000.0) + self.assertEqual(f(datetime.datetime(2010, 1, 1, 0, 0, 0, 128000)), + 1262304000.128000) + with self.assertRaises(TypeError): + f(None) + + def test_datetime_to_timestamp_string( + self, f=util.datetime_to_timestamp_string): self.assertEqual(f(util.EPOCH), "0") self.assertEqual(f(datetime.datetime(2010, 1, 1)), "1262304000") self.assertEqual(f(None), "") |
