Convert all the twisted.trial tests to pytest_twisted. Also move off of unittest.TestCase as well. Seems there were several tests which weren't actually testing what they should, and also some code that wasn't doing what the broken test said it should.
Goals:
Remove twisted.trial tests
Move to pytest fixtures, rather than many classess and subclasses with setup and teardown functions
Move away from self.assertX to assert style tests
FIx broken tests
Going forward I think these should be the goals when adding/modifying tests:
* Don't use BaseTest or set_up tear_down methods any more. Fixtures should be used either in the test module/class, or make/improve the ones available in conftest.py
* For sure don't use unittest or twisted.trial, they mess up the pytest stuff.
* Prefer pytest_twisted.ensureDeferred with an async function over inlineCallbacks.
- I think the async function syntax is nicer, and it helps catch silly mistakes, e.g. await None is invalid, but yield None isn't, so if some function returns an unexpected thing we try to await on, it will be caught earlier. (I struggled debugging a test for quite a while, then caught it immediately when switching to the new syntax)
- Once the maybe_coroutine PR goes in, using the async syntax can also improve tracebacks when debugging tests.
Things that should probably be cleaned up going forward:
* Remove BaseTestCase
* Remove the subclasses like DaemonBase in favor of new fixtures.
* I think there are some other utility subclasses that could be removed too
* Perhaps use parameterization in the ui_entry tests, rather that the weird combination of subclasses and the set_var fixture I mixed in.
* Convert some of the callback stuff to pytest_twisted.ensureDeferred tests, just for nicer readability
Details relating to pytest fixtures conftest.py in root dir:
* https://github.com/pytest-dev/pytest/issues/5822#issuecomment-697331920
* https://docs.pytest.org/en/latest/deprecations.html#pytest-plugins-in-non-top-level-conftest-files
Closes: https://github.com/deluge-torrent/deluge/pull/354
44 lines
1.6 KiB
Python
44 lines
1.6 KiB
Python
#
|
|
# Copyright (C) 2015 Calum Lind <calumlind@gmail.com>
|
|
#
|
|
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
|
|
# the additional special exception to link portions of this program with the OpenSSL library.
|
|
# See LICENSE for more details.
|
|
#
|
|
|
|
from deluge.pluginmanagerbase import PluginManagerBase
|
|
|
|
|
|
class TestPluginManagerBase:
|
|
def test_get_plugin_info(self):
|
|
pm = PluginManagerBase('core.conf', 'deluge.plugin.core')
|
|
for p in pm.get_available_plugins():
|
|
for key, value in pm.get_plugin_info(p).items():
|
|
assert isinstance(key, str)
|
|
assert isinstance(value, str)
|
|
|
|
def test_get_plugin_info_invalid_name(self):
|
|
pm = PluginManagerBase('core.conf', 'deluge.plugin.core')
|
|
for key, value in pm.get_plugin_info('random').items():
|
|
result = 'not available' if key in ('Name', 'Version') else ''
|
|
assert value == result
|
|
|
|
def test_parse_pkg_info_metadata_2_1(self):
|
|
pkg_info = """Metadata-Version: 2.1
|
|
Name: AutoAdd
|
|
Version: 1.8
|
|
Summary: Monitors folders for .torrent files.
|
|
Home-page: http://dev.deluge-torrent.org/wiki/Plugins/AutoAdd
|
|
Author: Chase Sterling, Pedro Algarvio
|
|
Author-email: chase.sterling@gmail.com, pedro@algarvio.me
|
|
License: GPLv3
|
|
Platform: UNKNOWN
|
|
|
|
Monitors folders for .torrent files.
|
|
"""
|
|
plugin_info = PluginManagerBase.parse_pkg_info(pkg_info)
|
|
for value in plugin_info.values():
|
|
assert value != ''
|
|
result = 'Monitors folders for .torrent files.'
|
|
assert plugin_info['Description'] == result
|