Skip to content

Commit

Permalink
py312 prep - Conversion of remaining unitest-style assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenton Taylor authored and brondsem committed Oct 30, 2024
1 parent 62a0ce3 commit 7b3ac92
Show file tree
Hide file tree
Showing 41 changed files with 239 additions and 232 deletions.
3 changes: 1 addition & 2 deletions Allura/allura/tests/model/test_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# under the License.

import os
from unittest import TestCase
from io import BytesIO

import ming
Expand All @@ -36,7 +35,7 @@ class __mongometa__:
Mapper.compile_all()


class TestFile(TestCase):
class TestFile:

def setup_method(self, method):
config = {
Expand Down
8 changes: 4 additions & 4 deletions Allura/allura/tests/model/test_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from forgewiki import model as WM


class TestNotification(unittest.TestCase):
class TestNotification:

def setup_method(self, method):
setup_basic_test()
Expand Down Expand Up @@ -164,7 +164,7 @@ def test_send_direct_wrong_project_context(self, sendmail):
)


class TestPostNotifications(unittest.TestCase):
class TestPostNotifications:

def setup_method(self, method):
setup_basic_test()
Expand Down Expand Up @@ -294,7 +294,7 @@ def _post_notification(self):
return M.Notification.post(self.pg, 'metadata')


class TestSubscriptionTypes(unittest.TestCase):
class TestSubscriptionTypes:

def setup_method(self, method):
setup_basic_test()
Expand Down Expand Up @@ -468,7 +468,7 @@ def test_send_digest_disabled_user(self, ref):
assert count == 1


class TestSiteNotification(unittest.TestCase):
class TestSiteNotification:
def setup_method(self, method):
self.note = M.SiteNotification(
active=True,
Expand Down
6 changes: 3 additions & 3 deletions Allura/allura/tests/model/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class RepoImplTestBase:
pass


class RepoTestBase(unittest.TestCase):
class RepoTestBase:
def setup_method(self, method):
setup_basic_test()

Expand Down Expand Up @@ -128,7 +128,7 @@ def test_clone_command_categories(self):
]


class TestLastCommit(unittest.TestCase):
class TestLastCommit:
def setup_method(self, method):
setup_basic_test()
setup_global_objects()
Expand Down Expand Up @@ -400,7 +400,7 @@ def test_loop(self):
assert lcd.by_name['file2'] == commit3._id


class TestModelCache(unittest.TestCase):
class TestModelCache:
def setup_method(self, method):
self.cache = M.repository.ModelCache()

Expand Down
3 changes: 1 addition & 2 deletions Allura/allura/tests/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# specific language governing permissions and limitations
# under the License.
import inspect
from unittest import TestCase
from mock import patch
import random
import gc
Expand All @@ -24,7 +23,7 @@
from alluratest.controller import setup_basic_test, setup_global_objects


class TestTask(TestCase):
class TestTask:

def setup_method(self, method):
setup_basic_test()
Expand Down
28 changes: 14 additions & 14 deletions Allura/allura/tests/test_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ def test_project_screenshots_macro(self):
assert 'src="/p/test/screenshot/test_file.jpg/thumb"' in r


class TestCachedMarkdown(unittest.TestCase):
class TestCachedMarkdown:

def setup_method(self, method):
setup()
Expand Down Expand Up @@ -815,7 +815,7 @@ def test_valid_cache(self):
with patch.object(self.md, 'convert') as convert_func:
html = self.md.cached_convert(self.post, 'text')
assert html == self.expected_html
self.assertIsInstance(html, Markup)
assert isinstance(html, Markup)
assert not convert_func.called
self.post.text = "text [[include]] pass"
html = self.md.cached_convert(self.post, 'text')
Expand Down Expand Up @@ -851,25 +851,25 @@ def test_cacheable_macro(self):
def test_no_threshold_defined(self):
html = self.md.cached_convert(self.post, 'text')
assert html == self.expected_html
self.assertIsNone(self.post.text_cache.md5)
self.assertIsNone(self.post.text_cache.html)
self.assertIsNone(self.post.text_cache.render_time)
assert self.post.text_cache.md5 is None
assert self.post.text_cache.html is None
assert self.post.text_cache.render_time is None

@patch.dict('allura.lib.app_globals.config', markdown_cache_threshold='foo')
def test_invalid_threshold(self):
html = self.md.cached_convert(self.post, 'text')
assert html == self.expected_html
self.assertIsNone(self.post.text_cache.md5)
self.assertIsNone(self.post.text_cache.html)
self.assertIsNone(self.post.text_cache.render_time)
assert self.post.text_cache.md5 is None
assert self.post.text_cache.html is None
assert self.post.text_cache.render_time is None

@patch.dict('allura.lib.app_globals.config', markdown_cache_threshold='99999')
def test_render_time_below_threshold(self):
html = self.md.cached_convert(self.post, 'text')
assert html == self.expected_html
self.assertIsNone(self.post.text_cache.md5)
self.assertIsNone(self.post.text_cache.html)
self.assertIsNone(self.post.text_cache.render_time)
assert self.post.text_cache.md5 is None
assert self.post.text_cache.html is None
assert self.post.text_cache.render_time is None

@patch.dict('allura.lib.app_globals.config', {})
def test_all_expected_keys_exist_in_cache(self):
Expand All @@ -879,7 +879,7 @@ def test_all_expected_keys_exist_in_cache(self):
assert required_keys == keys


class TestEmojis(unittest.TestCase):
class TestEmojis:

def test_markdown_emoji_atomic(self):
output = g.markdown.convert(':smile:')
Expand Down Expand Up @@ -914,7 +914,7 @@ def test_markdown_commit_with_emojis(self):
assert 'More emojis \U0001F44D\U0001F42B\U0001F552 wow!' in output


class TestUserMentions(unittest.TestCase):
class TestUserMentions:

def test_markdown_user_mention_default(self):
output = g.markdown.convert('Hello.. @nouser1, how are you?')
Expand Down Expand Up @@ -955,7 +955,7 @@ def test_markdown_user_mention_underscores(self, NeighborhoodProjectShortNameVal
assert 'class="user-mention"' in output


class TestHandlePaging(unittest.TestCase):
class TestHandlePaging:

def setup_method(self, method):
prefs = {}
Expand Down
8 changes: 4 additions & 4 deletions Allura/allura/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# under the License.

import io
from unittest import TestCase, skipIf
from unittest import skipIf
from os import path
from datetime import datetime, timedelta
import time
Expand Down Expand Up @@ -52,7 +52,7 @@ def setup_module():
setup_basic_test()


class TestMakeSafePathPortion(TestCase):
class TestMakeSafePathPortion:

def setup_method(self, method):
self.f = h.make_safe_path_portion
Expand Down Expand Up @@ -580,7 +580,7 @@ def test_login_overlay():
raise HTTPUnauthorized()


class TestIterEntryPoints(TestCase):
class TestIterEntryPoints:

def _make_ep(self, name, cls):
m = Mock()
Expand Down Expand Up @@ -683,7 +683,7 @@ def test_slugify():
assert h.slugify('Foo.Bar', True)[0] == 'Foo.Bar'


class TestRateLimit(TestCase):
class TestRateLimit:
rate_limits = '{"60": 1, "120": 3, "900": 5, "1800": 7, "3600": 10, "7200": 15, "86400": 20, "604800": 50, "2592000": 200}'
key_comment = 'allura.rate_limits_per_user'

Expand Down
2 changes: 1 addition & 1 deletion Allura/allura/tests/test_mail_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
return_path='forgemail.return_path')


class TestReactor(unittest.TestCase):
class TestReactor:

def setup_method(self, method):
setup_basic_test()
Expand Down
2 changes: 1 addition & 1 deletion Allura/allura/tests/test_scripttask.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from allura.scripts.scripttask import ScriptTask


class TestScriptTask(unittest.TestCase):
class TestScriptTask:

def setup_method(self, method):
class TestScriptTask(ScriptTask):
Expand Down
18 changes: 9 additions & 9 deletions Allura/allura/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@


@patch.dict('allura.lib.utils.tg.config', clear=True, foo='bar', baz='true')
class TestConfigProxy(unittest.TestCase):
class TestConfigProxy:

def setup_method(self, method):
self.cp = utils.ConfigProxy(mybaz="baz")
Expand All @@ -62,7 +62,7 @@ def test_get_bool(self):
assert self.cp.get_bool("fake") is False


class TestChunkedIterator(unittest.TestCase):
class TestChunkedIterator:

def setup_method(self, method):
setup_unit_test()
Expand Down Expand Up @@ -93,7 +93,7 @@ def test_filter_on_sort_key(self):
assert chunks[1][0].username == 'sample-user-3'


class TestChunkedList(unittest.TestCase):
class TestChunkedList:

def test_chunked_list(self):
l = list(range(10))
Expand All @@ -103,7 +103,7 @@ def test_chunked_list(self):
assert [el for sublist in chunks for el in sublist] == l


class TestAntispam(unittest.TestCase):
class TestAntispam:

def setup_method(self, method):
setup_unit_test()
Expand Down Expand Up @@ -168,7 +168,7 @@ def _encrypt_form(self, **kwargs):
return encrypted_form


class TestCaseInsensitiveDict(unittest.TestCase):
class TestCaseInsensitiveDict:

def test_everything(self):
d = utils.CaseInsensitiveDict(Foo=5)
Expand All @@ -187,7 +187,7 @@ def test_everything(self):
assert d == utils.CaseInsensitiveDict(Foo=1, bar=2)


class TestLineAnchorCodeHtmlFormatter(unittest.TestCase):
class TestLineAnchorCodeHtmlFormatter:

def test_render(self):
code = '#!/usr/bin/env python\n'\
Expand All @@ -207,7 +207,7 @@ def test_render(self):
assert '<span class="linenos">1</span>' in hl_code


class TestIsTextFile(unittest.TestCase):
class TestIsTextFile:

def test_is_text_file(self):
here_dir = path.dirname(__file__)
Expand All @@ -217,7 +217,7 @@ def test_is_text_file(self):
assert not utils.is_text_file(open(bin_file, 'rb').read())


class TestCodeStats(unittest.TestCase):
class TestCodeStats:

def setup_method(self, method):
setup_unit_test()
Expand All @@ -241,7 +241,7 @@ def greetings(self):
assert stats['code_size'] == len(blob.text)


class TestHTMLSanitizer(unittest.TestCase):
class TestHTMLSanitizer:

def walker_from_text(self, text):
parsed = html5lib.parseFragment(text)
Expand Down
Loading

0 comments on commit 7b3ac92

Please sign in to comment.