insert local directory into PYTHONPATH when running tests

pull/742/head
Mike Fährmann 4 years ago
parent 714566b6e3
commit 5df8f2959b
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -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():

@ -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):

@ -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):

@ -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)

@ -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)

@ -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"

@ -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):

@ -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

@ -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)

@ -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):

Loading…
Cancel
Save