From d505ebe92634733152522f4f3c595362d39977a8 Mon Sep 17 00:00:00 2001 From: bendikro Date: Thu, 9 Jun 2016 14:23:20 +0200 Subject: [PATCH] [Tests] Use common.rpath() in all tests --- deluge/tests/test_core.py | 23 ++++++++++------------- deluge/tests/test_httpdownloader.py | 3 --- deluge/tests/test_torrent.py | 8 ++++---- deluge/tests/test_torrentmanager.py | 3 +-- deluge/tests/test_ui_common.py | 7 ++++--- deluge/tests/test_web_api.py | 5 ++--- 6 files changed, 21 insertions(+), 28 deletions(-) diff --git a/deluge/tests/test_core.py b/deluge/tests/test_core.py index f23bf06b6..1bc8d8fb3 100644 --- a/deluge/tests/test_core.py +++ b/deluge/tests/test_core.py @@ -1,5 +1,4 @@ import base64 -import os from hashlib import sha1 as sha import pytest @@ -24,8 +23,6 @@ from .basetest import BaseTestCase common.disable_new_release_check() -rpath = common.rpath - class CookieResource(Resource): @@ -35,7 +32,7 @@ class CookieResource(Resource): return request.setHeader("Content-Type", "application/x-bittorrent") - with open(rpath("ubuntu-9.04-desktop-i386.iso.torrent")) as _file: + with open(common.rpath("ubuntu-9.04-desktop-i386.iso.torrent")) as _file: data = _file.read() return data @@ -43,7 +40,7 @@ class CookieResource(Resource): class PartialDownload(Resource): def render(self, request): - with open(rpath("ubuntu-9.04-desktop-i386.iso.torrent")) as _file: + with open(common.rpath("ubuntu-9.04-desktop-i386.iso.torrent")) as _file: data = _file.read() request.setHeader("Content-Type", len(data)) request.setHeader("Content-Type", "application/x-bittorrent") @@ -111,7 +108,7 @@ class CoreTestCase(BaseTestCase): filenames = ["test.torrent", "test_torrent.file.torrent"] files_to_add = [] for f in filenames: - filename = os.path.join(os.path.dirname(__file__), f) + filename = common.rpath(f) with open(filename) as _file: filedump = base64.encodestring(_file.read()) files_to_add.append((filename, filedump, options)) @@ -124,7 +121,7 @@ class CoreTestCase(BaseTestCase): filenames = ["test.torrent", "test.torrent"] files_to_add = [] for f in filenames: - filename = os.path.join(os.path.dirname(__file__), f) + filename = common.rpath(f) with open(filename) as _file: filedump = base64.encodestring(_file.read()) files_to_add.append((filename, filedump, options)) @@ -135,7 +132,7 @@ class CoreTestCase(BaseTestCase): @defer.inlineCallbacks def test_add_torrent_file(self): options = {} - filename = os.path.join(os.path.dirname(__file__), "test.torrent") + filename = common.rpath("test.torrent") with open(filename) as _file: filedump = base64.encodestring(_file.read()) torrent_id = yield self.core.add_torrent_file(filename, filedump, options) @@ -148,7 +145,7 @@ class CoreTestCase(BaseTestCase): def test_add_torrent_file_invalid_filedump(self): options = {} - filename = os.path.join(os.path.dirname(__file__), "test.torrent") + filename = common.rpath("test.torrent") self.assertRaises(AddTorrentError, self.core.add_torrent_file, filename, False, options) @defer.inlineCallbacks @@ -203,7 +200,7 @@ class CoreTestCase(BaseTestCase): @defer.inlineCallbacks def test_remove_torrent(self): options = {} - filename = os.path.join(os.path.dirname(__file__), "test.torrent") + filename = common.rpath("test.torrent") with open(filename) as _file: filedump = base64.encodestring(_file.read()) torrent_id = yield self.core.add_torrent_file(filename, filedump, options) @@ -217,12 +214,12 @@ class CoreTestCase(BaseTestCase): @defer.inlineCallbacks def test_remove_torrents(self): options = {} - filename = os.path.join(os.path.dirname(__file__), "test.torrent") + filename = common.rpath("test.torrent") with open(filename) as _file: filedump = base64.encodestring(_file.read()) torrent_id = yield self.core.add_torrent_file(filename, filedump, options) - filename2 = os.path.join(os.path.dirname(__file__), "unicode_filenames.torrent") + filename2 = common.rpath("unicode_filenames.torrent") with open(filename2) as _file: filedump = base64.encodestring(_file.read()) torrent_id2 = yield self.core.add_torrent_file(filename2, filedump, options) @@ -240,7 +237,7 @@ class CoreTestCase(BaseTestCase): @defer.inlineCallbacks def test_remove_torrents_invalid(self): options = {} - filename = os.path.join(os.path.dirname(__file__), "test.torrent") + filename = common.rpath("test.torrent") with open(filename) as _file: filedump = base64.encodestring(_file.read()) torrent_id = yield self.core.add_torrent_file(filename, filedump, options) diff --git a/deluge/tests/test_httpdownloader.py b/deluge/tests/test_httpdownloader.py index 6b500146a..3243943ce 100644 --- a/deluge/tests/test_httpdownloader.py +++ b/deluge/tests/test_httpdownloader.py @@ -14,8 +14,6 @@ from deluge.httpdownloader import download_file from deluge.log import setup_logger from deluge.ui.web.common import compress -from . import common - try: from twisted.web.resource import Resource except ImportError: @@ -23,7 +21,6 @@ except ImportError: from twisted.web.error import Resource -rpath = common.rpath temp_dir = tempfile.mkdtemp() diff --git a/deluge/tests/test_torrent.py b/deluge/tests/test_torrent.py index f477c2251..572e1afa5 100644 --- a/deluge/tests/test_torrent.py +++ b/deluge/tests/test_torrent.py @@ -52,7 +52,7 @@ class TorrentTestCase(BaseTestCase): self.assertEquals(torrent.state, state) def get_torrent_atp(self, filename): - filename = os.path.join(os.path.dirname(__file__), filename) + filename = common.rpath(filename) with open(filename, 'rb') as _file: info = lt.torrent_info(lt.bdecode(_file.read())) atp = {"ti": info} @@ -117,7 +117,7 @@ class TorrentTestCase(BaseTestCase): @defer.inlineCallbacks def test_torrent_error_data_missing(self): options = {"seed_mode": True} - filename = os.path.join(os.path.dirname(__file__), "test_torrent.file.torrent") + filename = common.rpath("test_torrent.file.torrent") with open(filename) as _file: filedump = base64.encodestring(_file.read()) torrent_id = yield self.core.add_torrent_file(filename, filedump, options) @@ -133,7 +133,7 @@ class TorrentTestCase(BaseTestCase): @defer.inlineCallbacks def test_torrent_error_resume_original_state(self): options = {"seed_mode": True, "add_paused": True} - filename = os.path.join(os.path.dirname(__file__), "test_torrent.file.torrent") + filename = common.rpath("test_torrent.file.torrent") with open(filename) as _file: filedump = base64.encodestring(_file.read()) torrent_id = yield self.core.add_torrent_file(filename, filedump, options) @@ -178,7 +178,7 @@ class TorrentTestCase(BaseTestCase): is_finished=True, ) - filename = os.path.join(os.path.dirname(__file__), "test_torrent.file.torrent") + filename = common.rpath("test_torrent.file.torrent") with open(filename) as _file: filedump = _file.read() torrent_id = yield self.core.torrentmanager.add(state=torrent_state, filedump=filedump, diff --git a/deluge/tests/test_torrentmanager.py b/deluge/tests/test_torrentmanager.py index ee620b679..cabd0bb57 100644 --- a/deluge/tests/test_torrentmanager.py +++ b/deluge/tests/test_torrentmanager.py @@ -1,5 +1,4 @@ import base64 -import os import warnings import pytest @@ -30,7 +29,7 @@ class TorrentmanagerTestCase(BaseTestCase): @defer.inlineCallbacks def test_remove_torrent(self): - filename = os.path.join(os.path.dirname(__file__), "test.torrent") + filename = common.rpath("test.torrent") with open(filename) as _file: filedump = base64.encodestring(_file.read()) torrent_id = yield self.core.add_torrent_file(filename, filedump, {}) diff --git a/deluge/tests/test_ui_common.py b/deluge/tests/test_ui_common.py index 838826984..09f2c940c 100644 --- a/deluge/tests/test_ui_common.py +++ b/deluge/tests/test_ui_common.py @@ -1,10 +1,11 @@ # -*- coding: utf-8 -*- -import os.path from twisted.trial import unittest from deluge.ui.common import TorrentInfo +from . import common + class UICommonTestCase(unittest.TestCase): def setUp(self): # NOQA @@ -14,12 +15,12 @@ class UICommonTestCase(unittest.TestCase): pass def test_utf8_encoded_paths(self): - filename = os.path.join(os.path.dirname(__file__), "test.torrent") + filename = common.rpath("test.torrent") ti = TorrentInfo(filename) self.assertTrue("azcvsupdater_2.6.2.jar" in ti.files_tree) def test_utf8_encoded_paths2(self): - filename = os.path.join(os.path.dirname(__file__), "unicode_filenames.torrent") + filename = common.rpath("unicode_filenames.torrent") ti = TorrentInfo(filename) files = ti.files_tree["unicode_filenames"] diff --git a/deluge/tests/test_web_api.py b/deluge/tests/test_web_api.py index 08cb48b01..18c03193e 100644 --- a/deluge/tests/test_web_api.py +++ b/deluge/tests/test_web_api.py @@ -7,7 +7,6 @@ # See LICENSE for more details. # -import os from StringIO import StringIO from twisted.internet import defer, reactor @@ -156,7 +155,7 @@ class WebAPITestCase(BaseTestCase, DaemonBase): self.assertFalse(self.deluge_web.web_api.remove_host(conn[0])) def test_get_torrent_info(self): - filename = os.path.join(os.path.dirname(__file__), "test.torrent") + filename = common.rpath("test.torrent") ret = self.deluge_web.web_api.get_torrent_info(filename) self.assertEquals(ret["name"], "azcvsupdater_2.6.2.jar") self.assertEquals(ret["info_hash"], "ab570cdd5a17ea1b61e970bb72047de141bce173") @@ -171,7 +170,7 @@ class WebAPITestCase(BaseTestCase, DaemonBase): @defer.inlineCallbacks def test_get_torrent_files(self): yield self.deluge_web.web_api.connect(self.host_id) - filename = os.path.join(os.path.dirname(__file__), "test.torrent") + filename = common.rpath("test.torrent") torrents = [{"path": filename, "options": {"download_location": "/home/deluge/"}}] yield self.deluge_web.web_api.add_torrents(torrents) ret = yield self.deluge_web.web_api.get_torrent_files("ab570cdd5a17ea1b61e970bb72047de141bce173")