diff --git a/test/test_cache.py b/test/test_cache.py index 31ece7e9..e19896e9 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 57679eab..cb202be2 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -7,12 +7,16 @@ # 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): diff --git a/test/test_cookies.py b/test/test_cookies.py index c39a5e65..f6919804 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 c43b533d..9393040d 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 e6f49632..043bd522 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 2ce5b431..58d4088c 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 629b0d7b..354f9ffe 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 bfed2ca9..046efc5f 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 03908236..4f31d81c 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 ffabd373..5fbaa4e1 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):