jenkins-bot has submitted this change and it was merged.
Change subject: [FEAT] tests: Use generic function to get path ......................................................................
[FEAT] tests: Use generic function to get path
To access tests file there are various constants like `_data_dir`. But in most cases `os.path.join` is used on them so it's more sensible to supply a function which takes the filename and returns the combined result. Except for the `_root_dir` all instances of `_*_dir` have been replaced by their `join_*_path` counterpart. It also adds `join_pages_path` for `tests/pages/`.
Change-Id: I409413a9a480f9bd149cb72a365e76cde7d8e3e7 --- M tests/__init__.py M tests/cache_tests.py M tests/data_ingestion_tests.py M tests/djvu_tests.py M tests/dry_api_tests.py M tests/fixes_tests.py M tests/http_tests.py M tests/pagegenerators_tests.py M tests/pwb_tests.py M tests/reflinks_tests.py M tests/replacebot_tests.py M tests/script_tests.py M tests/tools_tests.py M tests/upload_tests.py M tests/uploadbot_tests.py M tests/wikibase_tests.py M tests/xmlreader_tests.py 17 files changed, 92 insertions(+), 98 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/tests/__init__.py b/tests/__init__.py index 290914d..4416e05 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -9,10 +9,11 @@
__version__ = '$Id$'
+import functools import os import warnings
-__all__ = ('requests', '_cache_dir', 'TestRequest', +__all__ = ('requests', 'TestRequest', 'patch_request', 'unpatch_request')
# Verify that the unit tests have a base working environment: @@ -39,14 +40,33 @@ from pywikibot.data.api import Request as _original_Request from pywikibot.data.api import CachedRequest
-_tests_dir = os.path.split(__file__)[0] -_cache_dir = os.path.join(_tests_dir, 'apicache') -_data_dir = os.path.join(_tests_dir, 'data') -_images_dir = os.path.join(_data_dir, 'images') +_root_dir = os.path.split(os.path.split(__file__)[0])[0] + + +def join_root_path(*names): + """Return a path relative to the root directory.""" + return os.path.join(_root_dir, *names) + + +def create_path_func(base_func, subpath): + """Return a function returning a path relative to the given directory.""" + func = functools.partial(base_func, subpath) + func.path = base_func.path + '/' + subpath + func.__doc__ = 'Return a path relative to `{0}/`.'.format(func.path) + return func + + +join_root_path.path = 'root' +join_tests_path = create_path_func(join_root_path, 'tests') +join_cache_path = create_path_func(join_tests_path, 'apicache') +join_data_path = create_path_func(join_tests_path, 'data') +join_pages_path = create_path_func(join_tests_path, 'pages') + +join_images_path = create_path_func(join_data_path, 'images') +join_xml_data_path = create_path_func(join_data_path, 'xml')
# Find the root directory of the checkout -_root_dir = os.path.split(_tests_dir)[0] -_pwb_py = os.path.join(_root_dir, 'pwb.py') +_pwb_py = join_root_path('pwb.py')
library_test_modules = [ 'python', @@ -141,7 +161,7 @@
def _unknown_test_modules(): """List tests which are to be executed.""" - dir_list = os.listdir(_tests_dir) + dir_list = os.listdir(join_tests_path()) all_test_list = [name[0:-9] for name in dir_list # strip '_tests.py' if name.endswith('_tests.py') and not name.startswith('_')] # skip __init__.py and _* @@ -219,7 +239,7 @@
CachedRequest._get_cache_dir = classmethod( - lambda cls, *args: cls._make_dir(_cache_dir)) + lambda cls, *args: cls._make_dir(join_cache_path()))
# Travis-CI builds are set to retry twice, which aims to reduce the number diff --git a/tests/cache_tests.py b/tests/cache_tests.py index 70add5c..e4161f8 100644 --- a/tests/cache_tests.py +++ b/tests/cache_tests.py @@ -13,7 +13,7 @@ from pywikibot.site import BaseSite import scripts.maintenance.cache as cache
-from tests import _cache_dir +from tests import join_cache_path from tests.aspects import unittest, TestCase
@@ -37,7 +37,7 @@
def test_cache(self): """Test the apicache by doing _check_cache_entry over each entry.""" - cache.process_entries(_cache_dir, self._check_cache_entry) + cache.process_entries(join_cache_path(), self._check_cache_entry)
if __name__ == '__main__': diff --git a/tests/data_ingestion_tests.py b/tests/data_ingestion_tests.py index ee745a9..16c3ea5 100644 --- a/tests/data_ingestion_tests.py +++ b/tests/data_ingestion_tests.py @@ -10,9 +10,7 @@
__version__ = '$Id$'
-import os -from tests import _data_dir -from tests import _images_dir +from tests import join_data_path, join_images_path from tests.aspects import unittest, TestCase, ScriptMainTestCase from scripts import data_ingestion
@@ -46,7 +44,7 @@
def test_downloadPhoto(self): """Test download from http://upload.wikimedia.org/.""" - with open(os.path.join(_images_dir, 'MP_sounds.png'), 'rb') as f: + with open(join_images_path('MP_sounds.png'), 'rb') as f: self.assertEqual(f.read(), self.obj.downloadPhoto().read())
def test_findDuplicateImages(self): @@ -82,7 +80,7 @@ def setUp(self): """Set up unit test.""" super(TestCSVReader, self).setUp() - with open(os.path.join(_data_dir, 'csv_ingestion.csv')) as fileobj: + with open(join_data_path('csv_ingestion.csv')) as fileobj: self.iterator = data_ingestion.CSVReader(fileobj, 'url', site=self.get_site()) self.obj = next(self.iterator) diff --git a/tests/djvu_tests.py b/tests/djvu_tests.py index cbb3eb6..5d8da3e 100644 --- a/tests/djvu_tests.py +++ b/tests/djvu_tests.py @@ -10,14 +10,13 @@
from __future__ import absolute_import, unicode_literals
-import os import subprocess
-from tests import _data_dir +from tests import join_data_path, create_path_func from tests.aspects import unittest, TestCase from pywikibot.tools.djvu import DjVuFile
-_djvu_dir = 'djvu' +join_djvu_data_path = create_path_func(join_data_path, 'djvu')
class TestDjVuFile(TestCase): @@ -26,9 +25,9 @@
net = False
- file_djvu_not_existing = os.path.join(_data_dir, _djvu_dir, 'not_existing.djvu') - file_djvu = os.path.join(_data_dir, _djvu_dir, 'myfile.djvu') - file_djvu_wo_text = os.path.join(_data_dir, _djvu_dir, 'myfile_wo_text.djvu') + file_djvu_not_existing = join_djvu_data_path('not_existing.djvu') + file_djvu = join_djvu_data_path('myfile.djvu') + file_djvu_wo_text = join_djvu_data_path('myfile_wo_text.djvu') test_txt = 'A file with non-ASCII characters, \nlike é or ç'
@classmethod diff --git a/tests/dry_api_tests.py b/tests/dry_api_tests.py index 400a6f5..1831672 100644 --- a/tests/dry_api_tests.py +++ b/tests/dry_api_tests.py @@ -10,7 +10,6 @@ __version__ = '$Id$' #
-import os import datetime
import pywikibot @@ -22,7 +21,7 @@ ) from pywikibot.family import Family
-from tests import _images_dir +from tests import join_images_path from tests.utils import DummySiteinfo from tests.aspects import ( unittest, TestCase, DefaultDrySiteTestCase, SiteAttributeTestCase, @@ -272,7 +271,7 @@
def test_mime_file_payload(self): """Test Request._generate_MIME_part loads binary as binary.""" - local_filename = os.path.join(_images_dir, 'MP_sounds.png') + local_filename = join_images_path('MP_sounds.png') with open(local_filename, 'rb') as f: file_content = f.read() submsg = Request._generate_MIME_part( @@ -282,7 +281,7 @@
def test_mime_file_container(self): """Test Request._build_mime_request encodes binary.""" - local_filename = os.path.join(_images_dir, 'MP_sounds.png') + local_filename = join_images_path('MP_sounds.png') with open(local_filename, 'rb') as f: file_content = f.read() body = Request._build_mime_request({}, { @@ -304,7 +303,7 @@ site._userinfo = {'name': 'myusername', 'groups': []} req = Request(site=site, action="upload", file='MP_sounds.png', mime=True, - filename=os.path.join(_images_dir, 'MP_sounds.png')) + filename=join_images_path('MP_sounds.png')) self.assertEqual(req.mime, True)
diff --git a/tests/fixes_tests.py b/tests/fixes_tests.py index a7eda6d..26650ae 100644 --- a/tests/fixes_tests.py +++ b/tests/fixes_tests.py @@ -8,12 +8,10 @@ from __future__ import absolute_import, unicode_literals
__version__ = '$Id$' -# -import os
from pywikibot import fixes
-from tests import unittest, _data_dir +from tests import unittest, join_data_path from tests.aspects import TestCase
@@ -37,14 +35,14 @@ """Test loading a fix file overwriting the fixes.""" fixes.fixes = {} old_fixes = fixes.fixes - fixes._load_file(os.path.join(_data_dir, 'set-fixes.py')) + fixes._load_file(join_data_path('set-fixes.py')) self.assertIsNot(fixes.fixes, old_fixes)
def test_update_value(self): """Test loading a fix file changing the fixes.""" fixes.fixes = {} old_fixes = fixes.fixes - fixes._load_file(os.path.join(_data_dir, 'fixes.py')) + fixes._load_file(join_data_path('fixes.py')) self.assertIs(fixes.fixes, old_fixes)
diff --git a/tests/http_tests.py b/tests/http_tests.py index b912376..03a5092 100644 --- a/tests/http_tests.py +++ b/tests/http_tests.py @@ -9,7 +9,6 @@
__version__ = '$Id$'
-import os import re import warnings
@@ -24,7 +23,7 @@ UnicodeType as unicode, )
-from tests import _images_dir +from tests import join_images_path from tests.aspects import unittest, TestCase, DeprecationTestCase
@@ -371,7 +370,7 @@ """Set up test class.""" super(BinaryTestCase, cls).setUpClass()
- with open(os.path.join(_images_dir, 'MP_sounds.png'), 'rb') as f: + with open(join_images_path('MP_sounds.png'), 'rb') as f: cls.png = f.read()
def test_requests(self): diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py index 10181a4..1e8cd20 100755 --- a/tests/pagegenerators_tests.py +++ b/tests/pagegenerators_tests.py @@ -12,7 +12,6 @@ import calendar import datetime import json -import os import sys
from distutils.version import LooseVersion @@ -25,7 +24,7 @@ PreloadingGenerator, )
-from tests import _data_dir +from tests import join_data_path from tests.aspects import ( unittest, TestCase, @@ -275,7 +274,7 @@ )
def test_brackets(self): - filename = os.path.join(_data_dir, 'pagelist-brackets.txt') + filename = join_data_path('pagelist-brackets.txt') site = self.get_site() titles = list(pagegenerators.TextfilePageGenerator(filename, site)) self.assertEqual(len(titles), len(self.expected_titles)) @@ -285,7 +284,7 @@ self.assertPageTitlesEqual(titles, expected_titles)
def test_lines(self): - filename = os.path.join(_data_dir, 'pagelist-lines.txt') + filename = join_data_path('pagelist-lines.txt') site = self.get_site() titles = list(pagegenerators.TextfilePageGenerator(filename, site)) self.assertEqual(len(titles), len(self.expected_titles)) diff --git a/tests/pwb_tests.py b/tests/pwb_tests.py index 84718e3..94535f3 100644 --- a/tests/pwb_tests.py +++ b/tests/pwb_tests.py @@ -15,14 +15,13 @@
__version__ = '$Id$'
-import os import sys
-from tests import _tests_dir +from tests import join_tests_path, create_path_func from tests.utils import execute, execute_pwb from tests.aspects import unittest, PwbTestCase
-_pwb_tests_dir = os.path.join(_tests_dir, 'pwb') +join_pwb_tests_path = create_path_func(join_tests_path, 'pwb')
class TestPwb(PwbTestCase): @@ -42,7 +41,7 @@
def _do_check(self, name): package_name = 'tests.pwb.' + name - script_path = os.path.join(_pwb_tests_dir, name + '.py') + script_path = join_pwb_tests_path(name + '.py')
direct = execute([sys.executable, '-m', package_name]) vpwb = execute_pwb([script_path]) diff --git a/tests/reflinks_tests.py b/tests/reflinks_tests.py index 27023d0..603371f 100644 --- a/tests/reflinks_tests.py +++ b/tests/reflinks_tests.py @@ -9,14 +9,10 @@
__version__ = '$Id$'
-import os - from scripts.reflinks import XmlDumpPageGenerator, ReferencesRobot, main
-from tests import _data_dir +from tests import join_xml_data_path from tests.aspects import unittest, TestCase, ScriptMainTestCase - -_xml_data_dir = os.path.join(_data_dir, 'xml')
class TestXMLPageGenerator(TestCase): @@ -31,7 +27,7 @@ def test_non_bare_ref_urls(self): """Test pages without bare references are not processed.""" gen = XmlDumpPageGenerator( - xmlFilename=os.path.join(_xml_data_dir, 'article-pear-0.10.xml'), + xmlFilename=join_xml_data_path('article-pear-0.10.xml'), xmlStart=u'Pear', namespaces=[0, 1], site=self.get_site()) @@ -41,7 +37,7 @@ def test_simple_bare_refs(self): """Test simple bare references in multiple namespaces.""" gen = XmlDumpPageGenerator( - xmlFilename=os.path.join(_xml_data_dir, 'dummy-reflinks.xml'), + xmlFilename=join_xml_data_path('dummy-reflinks.xml'), xmlStart=u'Fake page', namespaces=[0, 1], site=self.get_site()) @@ -52,7 +48,7 @@ def test_namespace_empty_list(self): """Test namespaces=[] processes all namespaces.""" gen = XmlDumpPageGenerator( - xmlFilename=os.path.join(_xml_data_dir, 'dummy-reflinks.xml'), + xmlFilename=join_xml_data_path('dummy-reflinks.xml'), xmlStart=u'Fake page', namespaces=[], site=self.get_site()) @@ -64,7 +60,7 @@ def test_namespace_None(self): """Test namespaces=None processes all namespaces.""" gen = XmlDumpPageGenerator( - xmlFilename=os.path.join(_xml_data_dir, 'dummy-reflinks.xml'), + xmlFilename=join_xml_data_path('dummy-reflinks.xml'), xmlStart=u'Fake page', namespaces=None, site=self.get_site()) @@ -76,7 +72,7 @@ def test_namespace_string_ids(self): """Test namespaces with ids as string.""" gen = XmlDumpPageGenerator( - xmlFilename=os.path.join(_xml_data_dir, 'dummy-reflinks.xml'), + xmlFilename=join_xml_data_path('dummy-reflinks.xml'), xmlStart=u'Fake page', namespaces=["0", "1"], site=self.get_site()) @@ -87,7 +83,7 @@ def test_namespace_names(self): """Test namespaces with namespace names.""" gen = XmlDumpPageGenerator( - xmlFilename=os.path.join(_xml_data_dir, 'dummy-reflinks.xml'), + xmlFilename=join_xml_data_path('dummy-reflinks.xml'), xmlStart=u'Fake page', namespaces=["Talk"], site=self.get_site()) @@ -99,7 +95,7 @@ def test_start_with_underscore(self): """Test with underscore in start page title.""" gen = XmlDumpPageGenerator( - xmlFilename=os.path.join(_xml_data_dir, 'dummy-reflinks.xml'), + xmlFilename=join_xml_data_path('dummy-reflinks.xml'), xmlStart=u'Fake_page', namespaces=[0, 1], site=self.get_site()) @@ -110,7 +106,7 @@ def test_without_start(self): """Test without a start page title.""" gen = XmlDumpPageGenerator( - xmlFilename=os.path.join(_xml_data_dir, 'dummy-reflinks.xml'), + xmlFilename=join_xml_data_path('dummy-reflinks.xml'), xmlStart=None, namespaces=[0, 1], site=self.get_site()) @@ -122,7 +118,7 @@ def test_start_prefix(self): """Test with a prefix as a start page title.""" gen = XmlDumpPageGenerator( - xmlFilename=os.path.join(_xml_data_dir, 'dummy-reflinks.xml'), + xmlFilename=join_xml_data_path('dummy-reflinks.xml'), xmlStart='Fake', namespaces=[0, 1], site=self.get_site()) @@ -160,14 +156,14 @@
def test_xml_simple(self): """Test the generator without any narrowing.""" - main('-xml:' + os.path.join(_xml_data_dir, 'dummy-reflinks.xml')) + main('-xml:' + join_xml_data_path('dummy-reflinks.xml')) gen = self.constructor_args[0] self.assertPageTitlesCountEqual(gen, [u'Fake page', u'Talk:Fake page'], site=self.get_site())
def test_xml_one_namespace(self): """Test the generator using one namespace id.""" - main('-xml:' + os.path.join(_xml_data_dir, 'dummy-reflinks.xml'), + main('-xml:' + join_xml_data_path('dummy-reflinks.xml'), '-namespace:1') gen = self.constructor_args[0] pages = list(gen) @@ -176,7 +172,7 @@
def test_xml_multiple_namespace_ids(self): """Test the generator using multiple separate namespaces parameters.""" - main('-xml:' + os.path.join(_xml_data_dir, 'dummy-reflinks.xml'), + main('-xml:' + join_xml_data_path('dummy-reflinks.xml'), '-namespace:0', '-namespace:1', '-xmlstart:Fake page') gen = self.constructor_args[0] self.assertPageTitlesCountEqual(gen, [u'Fake page', u'Talk:Fake page'], @@ -185,7 +181,7 @@ @unittest.expectedFailure def test_xml_multiple_namespace_ids_2(self): """Test the generator using multiple namespaces in one parameter.""" - main('-xml:' + os.path.join(_xml_data_dir, 'dummy-reflinks.xml'), + main('-xml:' + join_xml_data_path('dummy-reflinks.xml'), '-namespace:0,1', '-xmlstart:Fake page') gen = self.constructor_args[0] self.assertPageTitlesCountEqual(gen, [u'Fake page', u'Talk:Fake page'], @@ -194,7 +190,7 @@ @unittest.expectedFailure def test_xml_start_prefix(self): """Test the generator using a start partial page.""" - main('-xml:' + os.path.join(_xml_data_dir, 'dummy-reflinks.xml'), + main('-xml:' + join_xml_data_path('dummy-reflinks.xml'), '-namespace:1', '-xmlstart:Fake') gen = self.constructor_args[0] pages = list(gen) @@ -204,7 +200,7 @@ @unittest.expectedFailure def test_xml_start_underscore(self): """Test the generator using a start page with an underscore.""" - main('-xml:' + os.path.join(_xml_data_dir, 'dummy-reflinks.xml'), + main('-xml:' + join_xml_data_path('dummy-reflinks.xml'), '-namespace:1', '-xmlstart:Fake_page') gen = self.constructor_args[0] pages = list(gen) @@ -213,7 +209,7 @@
def test_xml_namespace_name(self): """Test the generator using a namespace name.""" - main('-xml:' + os.path.join(_xml_data_dir, 'dummy-reflinks.xml'), + main('-xml:' + join_xml_data_path('dummy-reflinks.xml'), '-namespace:Talk', '-xmlstart:Fake page') gen = self.constructor_args[0] pages = list(gen) diff --git a/tests/replacebot_tests.py b/tests/replacebot_tests.py index 8794795..ffebe76 100644 --- a/tests/replacebot_tests.py +++ b/tests/replacebot_tests.py @@ -8,8 +8,6 @@ from __future__ import absolute_import, unicode_literals
__version__ = '$Id$' -# -import os
import pywikibot
@@ -17,13 +15,13 @@
from scripts import replace
-from tests import _data_dir +from tests import join_data_path from tests.aspects import unittest from tests.bot_tests import TWNBotTestCase
# Load only the custom fixes fixes.fixes.clear() -fixes._load_file(os.path.join(_data_dir, 'fixes.py')) +fixes._load_file(join_data_path('fixes.py'))
class TestReplacementsMain(TWNBotTestCase): diff --git a/tests/script_tests.py b/tests/script_tests.py index 9dfcc94..6a2eb11 100644 --- a/tests/script_tests.py +++ b/tests/script_tests.py @@ -17,11 +17,11 @@ StringTypes, )
-from tests import _root_dir +from tests import join_root_path from tests.aspects import unittest, DefaultSiteTestCase, MetaTestCaseClass, PwbTestCase from tests.utils import allowed_failure, execute_pwb, add_metaclass
-scripts_path = os.path.join(_root_dir, 'scripts') +scripts_path = join_root_path('scripts')
# These dependencies are not always the package name which is in setup.py. # e.g. 'PIL.ImageTk' is a object provided by several different pypi packages, diff --git a/tests/tools_tests.py b/tests/tools_tests.py index acbb7ac..9b2445a 100644 --- a/tests/tools_tests.py +++ b/tests/tools_tests.py @@ -17,11 +17,9 @@
from pywikibot import tools
-from tests import _data_dir +from tests import join_xml_data_path from tests.aspects import unittest, DeprecationTestCase, TestCase from tests.utils import expected_failure_if - -_xml_data_dir = os.path.join(_data_dir, 'xml')
class ContextManagerWrapperTestCase(TestCase): @@ -87,7 +85,7 @@ def setUpClass(cls): """Define base_file and original_content.""" super(OpenArchiveTestCase, cls).setUpClass() - cls.base_file = os.path.join(_xml_data_dir, 'article-pyrus.xml') + cls.base_file = join_xml_data_path('article-pyrus.xml') with open(cls.base_file, 'rb') as f: cls.original_content = f.read()
@@ -150,7 +148,7 @@ def setUpClass(cls): """Define base_file and original_content.""" super(OpenArchiveWriteTestCase, cls).setUpClass() - cls.base_file = os.path.join(_xml_data_dir, 'article-pyrus.xml') + cls.base_file = join_xml_data_path('article-pyrus.xml') with open(cls.base_file, 'rb') as f: cls.original_content = f.read()
diff --git a/tests/upload_tests.py b/tests/upload_tests.py index 610a9d8..a7987d8 100644 --- a/tests/upload_tests.py +++ b/tests/upload_tests.py @@ -13,13 +13,11 @@
__version__ = '$Id$'
-import os - import pywikibot
from pywikibot.data.api import APIError
-from tests import _images_dir +from tests import join_images_path from tests.aspects import unittest, TestCase
@@ -32,22 +30,20 @@ family = 'wikipedia' code = 'test'
- sounds_png = os.path.join(_images_dir, 'MP_sounds.png') - arrow_png = os.path.join(_images_dir, '1rightarrow.png') + sounds_png = join_images_path('MP_sounds.png') + arrow_png = join_images_path('1rightarrow.png')
def test_png(self): """Test uploading a png using Site.upload.""" page = pywikibot.FilePage(self.site, 'MP_sounds-pwb.png') - local_filename = os.path.join(_images_dir, 'MP_sounds.png') - self.site.upload(page, source_filename=local_filename, + self.site.upload(page, source_filename=self.sounds_png, comment='pywikibot test', ignore_warnings=True)
def test_png_chunked(self): """Test uploading a png in two chunks using Site.upload.""" page = pywikibot.FilePage(self.site, 'MP_sounds-pwb-chunked.png') - local_filename = os.path.join(_images_dir, 'MP_sounds.png') - self.site.upload(page, source_filename=local_filename, + self.site.upload(page, source_filename=self.sounds_png, comment='pywikibot test', ignore_warnings=True, chunk_size=1024)
diff --git a/tests/uploadbot_tests.py b/tests/uploadbot_tests.py index a1da9de..67e95c3 100644 --- a/tests/uploadbot_tests.py +++ b/tests/uploadbot_tests.py @@ -17,7 +17,7 @@ import os
from scripts import upload -from tests import _images_dir +from tests import join_images_path from tests.aspects import unittest, TestCase
@@ -33,7 +33,7 @@ def test_png_list(self): """Test uploading a list of pngs using upload.py.""" image_list = [] - for directory_info in os.walk(_images_dir): + for directory_info in os.walk(join_images_path()): for dir_file in directory_info[2]: image_list.append(os.path.join(directory_info[0], dir_file)) bot = upload.UploadRobot(url=image_list, @@ -45,7 +45,7 @@
def test_png(self): """Test uploading a png using upload.py.""" - bot = upload.UploadRobot(url=[os.path.join(_images_dir, "MP_sounds.png")], + bot = upload.UploadRobot(url=[join_images_path("MP_sounds.png")], description="pywikibot upload.py script test", useFilename=None, keepFilename=True, verifyDescription=True, aborts=set(), diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py index 248d324..406a42d 100644 --- a/tests/wikibase_tests.py +++ b/tests/wikibase_tests.py @@ -12,7 +12,6 @@
import copy import json -import os
import pywikibot
@@ -20,6 +19,7 @@ from pywikibot.page import WikibasePage, ItemPage from pywikibot.site import Namespace, NamespacesDict
+from tests import join_pages_path from tests.aspects import ( unittest, TestCase, WikidataTestCase, @@ -650,7 +650,7 @@ super(TestLinks, self).setUp() self.wdp = pywikibot.ItemPage(self.get_repo(), 'Q60') self.wdp.id = 'Q60' - with open(os.path.join(os.path.split(__file__)[0], 'pages', 'Q60_only_sitelinks.wd')) as f: + with open(join_pages_path('Q60_only_sitelinks.wd')) as f: self.wdp._content = json.load(f) self.wdp.get()
@@ -968,7 +968,7 @@ wikidata = self.get_repo() self.wdp = pywikibot.ItemPage(wikidata, 'Q60') self.wdp.id = 'Q60' - with open(os.path.join(os.path.split(__file__)[0], 'pages', 'Q60.wd')) as f: + with open(join_pages_path('Q60.wd')) as f: self.wdp._content = json.load(f) self.wdp.get() del self.wdp._content['id'] diff --git a/tests/xmlreader_tests.py b/tests/xmlreader_tests.py index 3f11ba8..00fe478 100644 --- a/tests/xmlreader_tests.py +++ b/tests/xmlreader_tests.py @@ -9,14 +9,10 @@
__version__ = '$Id$'
-import os.path - from pywikibot import xmlreader
-from tests import _data_dir +from tests import join_xml_data_path from tests.aspects import unittest, TestCase - -_xml_data_dir = os.path.join(_data_dir, 'xml')
class XmlReaderTestCase(TestCase): @@ -28,7 +24,7 @@ def _get_entries(self, filename, **kwargs): """Get all entries via XmlDump.""" entries = [r for r in - xmlreader.XmlDump(os.path.join(_xml_data_dir, filename), + xmlreader.XmlDump(join_xml_data_path(filename), **kwargs).parse()] return entries
@@ -62,8 +58,7 @@ """Test XmlDump correctly parsing whether a page is a redirect.""" pages = self._get_entries('article-pyrus.xml', allrevisions=True) pages = [r for r in - xmlreader.XmlDump(os.path.join(_xml_data_dir, - "article-pyrus.xml")).parse()] + xmlreader.XmlDump(join_xml_data_path('article-pyrus.xml')).parse()] self.assertTrue(pages[0].isredirect)
def _compare(self, previous, variant, all_revisions):
pywikibot-commits@lists.wikimedia.org