aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@gmail.com>2020-05-03 00:06:40 -0400
committerLibravatarUnit 193 <unit193@gmail.com>2020-05-03 00:06:40 -0400
commit90e50db2e3c38f523bb5195d295290b06e5cedb0 (patch)
tree4759dc0faea79f83fa5074e2d0bd82b18a9caaea /test
parentd5b96ce44b7809f5ae01e3e9d70a1d58fe21ccf5 (diff)
New upstream version 1.13.6upstream/1.13.6
Diffstat (limited to 'test')
-rw-r--r--test/test_cache.py11
-rw-r--r--test/test_config.py31
-rw-r--r--test/test_cookies.py6
-rw-r--r--test/test_downloader.py23
-rw-r--r--test/test_extractor.py25
-rw-r--r--test/test_oauth.py7
-rw-r--r--test/test_postprocessor.py15
-rw-r--r--test/test_results.py7
-rw-r--r--test/test_text.py6
-rw-r--r--test/test_util.py7
10 files changed, 93 insertions, 45 deletions
diff --git a/test/test_cache.py b/test/test_cache.py
index 31ece7e..e19896e 100644
--- a/test/test_cache.py
+++ b/test/test_cache.py
@@ -7,14 +7,19 @@
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
+import os
+import sys
import unittest
-import tempfile
+
import time
+import tempfile
+
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from gallery_dl import config, util # noqa E402
-from gallery_dl import config, util
dbpath = tempfile.mkstemp()[1]
config.set(("cache",), "file", dbpath)
-from gallery_dl import cache # noqa
+from gallery_dl import cache # noqa E402
def tearDownModule():
diff --git a/test/test_config.py b/test/test_config.py
index a9d3f54..cb202be 100644
--- a/test/test_config.py
+++ b/test/test_config.py
@@ -1,17 +1,22 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-# Copyright 2015-2019 Mike Fährmann
+# Copyright 2015-2020 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
# published by the Free Software Foundation.
-import unittest
-import gallery_dl.config as config
import os
+import sys
+import unittest
+
+import json
import tempfile
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from gallery_dl import config # noqa E402
+
class TestConfig(unittest.TestCase):
@@ -137,5 +142,25 @@ class TestConfig(unittest.TestCase):
self.assertEqual(config.get(("b",), "e"), "foo")
+class TestConfigFiles(unittest.TestCase):
+
+ def test_default_config(self):
+ cfg = self._load("gallery-dl.conf")
+ self.assertIsInstance(cfg, dict)
+ self.assertTrue(cfg)
+
+ def test_example_config(self):
+ cfg = self._load("gallery-dl-example.conf")
+ self.assertIsInstance(cfg, dict)
+ self.assertTrue(cfg)
+
+ @staticmethod
+ def _load(name):
+ rootdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+ path = os.path.join(rootdir, "docs", name)
+ with open(path) as fp:
+ return json.load(fp)
+
+
if __name__ == '__main__':
unittest.main()
diff --git a/test/test_cookies.py b/test/test_cookies.py
index c39a5e6..f691980 100644
--- a/test/test_cookies.py
+++ b/test/test_cookies.py
@@ -7,6 +7,8 @@
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
+import os
+import sys
import unittest
from unittest import mock
@@ -14,8 +16,8 @@ import logging
import tempfile
from os.path import join
-import gallery_dl.config as config
-import gallery_dl.extractor as extractor
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from gallery_dl import config, extractor # noqa E402
class TestCookiejar(unittest.TestCase):
diff --git a/test/test_downloader.py b/test/test_downloader.py
index c43b533..9393040 100644
--- a/test/test_downloader.py
+++ b/test/test_downloader.py
@@ -1,29 +1,28 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-# Copyright 2018 Mike Fährmann
+# Copyright 2018-2020 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
# published by the Free Software Foundation.
-import re
+import os
import sys
+import unittest
+from unittest.mock import Mock, MagicMock, patch
+
+import re
import base64
import os.path
import tempfile
import threading
import http.server
-import unittest
-from unittest.mock import Mock, MagicMock, patch
-
-import gallery_dl.downloader as downloader
-import gallery_dl.extractor as extractor
-import gallery_dl.config as config
-from gallery_dl.downloader.common import DownloaderBase
-from gallery_dl.output import NullOutput
-from gallery_dl.util import PathFormat
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from gallery_dl import downloader, extractor, config, util # noqa E402
+from gallery_dl.downloader.common import DownloaderBase # noqa E402
+from gallery_dl.output import NullOutput # noqa E402
class MockDownloaderModule(Mock):
@@ -119,7 +118,7 @@ class TestDownloaderBase(unittest.TestCase):
"filename": name,
"extension": extension,
}
- pathfmt = PathFormat(cls.extractor)
+ pathfmt = util.PathFormat(cls.extractor)
pathfmt.set_directory(kwdict)
pathfmt.set_filename(kwdict)
diff --git a/test/test_extractor.py b/test/test_extractor.py
index e6f4963..043bd52 100644
--- a/test/test_extractor.py
+++ b/test/test_extractor.py
@@ -7,18 +7,20 @@
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
+import os
import sys
+import unittest
+from unittest.mock import patch
+
import time
import string
from datetime import datetime, timedelta
-import unittest
-from unittest.mock import patch
-
-from gallery_dl import extractor
-from gallery_dl.extractor import mastodon
-from gallery_dl.extractor.common import Extractor, Message
-from gallery_dl.extractor.directlink import DirectlinkExtractor as DLExtractor
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from gallery_dl import extractor # 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
class FakeExtractor(Extractor):
@@ -78,7 +80,7 @@ class TestExtractorModule(unittest.TestCase):
test_uri = "test:"
fake_uri = "fake:"
- self.assertIsInstance(extractor.find(link_uri), DLExtractor)
+ self.assertIsInstance(extractor.find(link_uri), DirectlinkExtractor)
self.assertIsInstance(extractor.find(test_uri), Extractor)
self.assertIsNone(extractor.find(fake_uri))
@@ -87,12 +89,12 @@ class TestExtractorModule(unittest.TestCase):
self.assertIsInstance(extractor.find(test_uri), Extractor)
self.assertIsNone(extractor.find(fake_uri))
- with extractor.blacklist([], [DLExtractor, FakeExtractor]):
+ with extractor.blacklist([], [DirectlinkExtractor, FakeExtractor]):
self.assertIsNone(extractor.find(link_uri))
self.assertIsInstance(extractor.find(test_uri), Extractor)
self.assertIsNone(extractor.find(fake_uri))
- with extractor.blacklist(["test"], [DLExtractor]):
+ with extractor.blacklist(["test"], [DirectlinkExtractor]):
self.assertIsNone(extractor.find(link_uri))
self.assertIsNone(extractor.find(test_uri))
self.assertIsNone(extractor.find(fake_uri))
@@ -127,7 +129,8 @@ class TestExtractorModule(unittest.TestCase):
for extr2 in extractor._cache:
# skip DirectlinkExtractor pattern if it isn't tested
- if extr1 != DLExtractor and extr2 == DLExtractor:
+ if extr1 != DirectlinkExtractor and \
+ extr2 == DirectlinkExtractor:
continue
match = extr2.pattern.match(url)
diff --git a/test/test_oauth.py b/test/test_oauth.py
index 2ce5b43..58d4088 100644
--- a/test/test_oauth.py
+++ b/test/test_oauth.py
@@ -1,15 +1,18 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-# Copyright 2018 Mike Fährmann
+# Copyright 2018-2020 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
# published by the Free Software Foundation.
+import os
+import sys
import unittest
-from gallery_dl import oauth, text
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from gallery_dl import oauth, text # noqa E402
TESTSERVER = "http://term.ie/oauth/example"
CONSUMER_KEY = "key"
diff --git a/test/test_postprocessor.py b/test/test_postprocessor.py
index 629b0d7..354f9ff 100644
--- a/test/test_postprocessor.py
+++ b/test/test_postprocessor.py
@@ -1,23 +1,24 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
-# Copyright 2019 Mike Fährmann
+# Copyright 2019-2020 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
# published by the Free Software Foundation.
import os
-import os.path
+import sys
+import unittest
+from unittest.mock import Mock, mock_open, patch
+
import zipfile
import tempfile
from datetime import datetime, timezone as tz
-import unittest
-from unittest.mock import Mock, mock_open, patch
-
-from gallery_dl import postprocessor, extractor, util, config
-from gallery_dl.postprocessor.common import PostProcessor
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from gallery_dl import postprocessor, extractor, util, config # noqa E402
+from gallery_dl.postprocessor.common import PostProcessor # noqa E402
class MockPostprocessorModule(Mock):
diff --git a/test/test_results.py b/test/test_results.py
index bfed2ca..046efc5 100644
--- a/test/test_results.py
+++ b/test/test_results.py
@@ -9,12 +9,15 @@
import os
import sys
+import unittest
+
import re
import json
import hashlib
import datetime
-import unittest
-from gallery_dl import extractor, util, job, config, exception
+
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from gallery_dl import extractor, util, job, config, exception # noqa E402
# these don't work on Travis CI
diff --git a/test/test_text.py b/test/test_text.py
index 0390823..4f31d81 100644
--- a/test/test_text.py
+++ b/test/test_text.py
@@ -7,10 +7,14 @@
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
+import os
+import sys
import unittest
+
import datetime
-from gallery_dl import text
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from gallery_dl import text # noqa E402
INVALID = ((), [], {}, None, 1, 2.3)
diff --git a/test/test_util.py b/test/test_util.py
index ffabd37..5fbaa4e 100644
--- a/test/test_util.py
+++ b/test/test_util.py
@@ -7,14 +7,17 @@
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
-import unittest
+import os
import sys
+import unittest
+
import io
import random
import string
import http.cookiejar
-from gallery_dl import util, text, exception
+sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+from gallery_dl import util, text, exception # noqa E402
class TestRange(unittest.TestCase):