3
0
Fork 0

fix: format all code with black

and from now on should not deviate from that...
This commit is contained in:
Lance Edgar 2025-08-30 21:25:44 -05:00
parent 49f9a0228b
commit a6bb538ce9
59 changed files with 2762 additions and 2131 deletions

View file

@ -10,9 +10,17 @@ from wuttjamaican import util as mod
from wuttjamaican.progress import ProgressBase
class A: pass
class B(A): pass
class C(B): pass
class A:
pass
class B(A):
pass
class C(B):
pass
class TestGetClassHierarchy(TestCase):
@ -35,15 +43,15 @@ class TestLoadEntryPoints(TestCase):
def test_empty(self):
# empty set returned for unknown group
result = mod.load_entry_points('this_should_never_exist!!!!!!')
result = mod.load_entry_points("this_should_never_exist!!!!!!")
self.assertEqual(result, {})
def test_basic(self):
# load some entry points which should "always" be present,
# even in a testing environment. basic sanity check
result = mod.load_entry_points('console_scripts', ignore_errors=True)
result = mod.load_entry_points("console_scripts", ignore_errors=True)
self.assertTrue(len(result) >= 1)
self.assertIn('pip', result)
self.assertIn("pip", result)
def test_basic_pre_python_3_10(self):
@ -54,6 +62,7 @@ class TestLoadEntryPoints(TestCase):
pytest.skip("this test is not relevant before python 3.10")
import importlib.metadata
real_entry_points = importlib.metadata.entry_points()
class FakeEntryPoints(dict):
@ -63,13 +72,13 @@ class TestLoadEntryPoints(TestCase):
importlib = MagicMock()
importlib.metadata.entry_points.return_value = FakeEntryPoints()
with patch.dict('sys.modules', **{'importlib': importlib}):
with patch.dict("sys.modules", **{"importlib": importlib}):
# load some entry points which should "always" be present,
# even in a testing environment. basic sanity check
result = mod.load_entry_points('console_scripts', ignore_errors=True)
result = mod.load_entry_points("console_scripts", ignore_errors=True)
self.assertTrue(len(result) >= 1)
self.assertIn('pytest', result)
self.assertIn("pytest", result)
def test_basic_pre_python_3_8(self):
@ -80,11 +89,12 @@ class TestLoadEntryPoints(TestCase):
pytest.skip("this test is not relevant before python 3.8")
from importlib.metadata import entry_points
real_entry_points = entry_points()
class FakeEntryPoints(dict):
def get(self, group, default):
if hasattr(real_entry_points, 'select'):
if hasattr(real_entry_points, "select"):
return real_entry_points.select(group=group)
return real_entry_points.get(group, [])
@ -94,19 +104,19 @@ class TestLoadEntryPoints(TestCase):
orig_import = __import__
def mock_import(name, *args, **kwargs):
if name == 'importlib.metadata':
if name == "importlib.metadata":
raise ImportError
if name == 'importlib_metadata':
if name == "importlib_metadata":
return importlib_metadata
return orig_import(name, *args, **kwargs)
with patch('builtins.__import__', side_effect=mock_import):
with patch("builtins.__import__", side_effect=mock_import):
# load some entry points which should "always" be present,
# even in a testing environment. basic sanity check
result = mod.load_entry_points('console_scripts', ignore_errors=True)
result = mod.load_entry_points("console_scripts", ignore_errors=True)
self.assertTrue(len(result) >= 1)
self.assertIn('pytest', result)
self.assertIn("pytest", result)
def test_error(self):
@ -123,22 +133,24 @@ class TestLoadEntryPoints(TestCase):
importlib = MagicMock()
importlib.metadata.entry_points.return_value = entry_points
with patch.dict('sys.modules', **{'importlib': importlib}):
with patch.dict("sys.modules", **{"importlib": importlib}):
# empty set returned if errors suppressed
result = mod.load_entry_points('wuttatest.thingers', ignore_errors=True)
result = mod.load_entry_points("wuttatest.thingers", ignore_errors=True)
self.assertEqual(result, {})
importlib.metadata.entry_points.assert_called_once_with()
entry_points.select.assert_called_once_with(group='wuttatest.thingers')
entry_points.select.assert_called_once_with(group="wuttatest.thingers")
entry_point.load.assert_called_once_with()
# error is raised, if not suppressed
importlib.metadata.entry_points.reset_mock()
entry_points.select.reset_mock()
entry_point.load.reset_mock()
self.assertRaises(NotImplementedError, mod.load_entry_points, 'wuttatest.thingers')
self.assertRaises(
NotImplementedError, mod.load_entry_points, "wuttatest.thingers"
)
importlib.metadata.entry_points.assert_called_once_with()
entry_points.select.assert_called_once_with(group='wuttatest.thingers')
entry_points.select.assert_called_once_with(group="wuttatest.thingers")
entry_point.load.assert_called_once_with()
@ -148,7 +160,7 @@ class TestLoadObject(TestCase):
self.assertRaises(ValueError, mod.load_object, None)
def test_basic(self):
result = mod.load_object('unittest:TestCase')
result = mod.load_object("unittest:TestCase")
self.assertIs(result, TestCase)
@ -169,20 +181,20 @@ class TestParseBool(TestCase):
self.assertFalse(mod.parse_bool(False))
def test_string_true(self):
self.assertTrue(mod.parse_bool('true'))
self.assertTrue(mod.parse_bool('yes'))
self.assertTrue(mod.parse_bool('y'))
self.assertTrue(mod.parse_bool('on'))
self.assertTrue(mod.parse_bool('1'))
self.assertTrue(mod.parse_bool("true"))
self.assertTrue(mod.parse_bool("yes"))
self.assertTrue(mod.parse_bool("y"))
self.assertTrue(mod.parse_bool("on"))
self.assertTrue(mod.parse_bool("1"))
def test_string_false(self):
self.assertFalse(mod.parse_bool('false'))
self.assertFalse(mod.parse_bool('no'))
self.assertFalse(mod.parse_bool('n'))
self.assertFalse(mod.parse_bool('off'))
self.assertFalse(mod.parse_bool('0'))
self.assertFalse(mod.parse_bool("false"))
self.assertFalse(mod.parse_bool("no"))
self.assertFalse(mod.parse_bool("n"))
self.assertFalse(mod.parse_bool("off"))
self.assertFalse(mod.parse_bool("0"))
# nb. assume false for unrecognized input
self.assertFalse(mod.parse_bool('whatever-else'))
self.assertFalse(mod.parse_bool("whatever-else"))
class TestParseList(TestCase):
@ -198,76 +210,82 @@ class TestParseList(TestCase):
self.assertIs(value, mylist)
def test_single_value(self):
value = mod.parse_list('foo')
value = mod.parse_list("foo")
self.assertEqual(len(value), 1)
self.assertEqual(value[0], 'foo')
self.assertEqual(value[0], "foo")
def test_single_value_padded_by_spaces(self):
value = mod.parse_list(' foo ')
value = mod.parse_list(" foo ")
self.assertEqual(len(value), 1)
self.assertEqual(value[0], 'foo')
self.assertEqual(value[0], "foo")
def test_slash_is_not_a_separator(self):
value = mod.parse_list('/dev/null')
value = mod.parse_list("/dev/null")
self.assertEqual(len(value), 1)
self.assertEqual(value[0], '/dev/null')
self.assertEqual(value[0], "/dev/null")
def test_multiple_values_separated_by_whitespace(self):
value = mod.parse_list('foo bar baz')
value = mod.parse_list("foo bar baz")
self.assertEqual(len(value), 3)
self.assertEqual(value[0], 'foo')
self.assertEqual(value[1], 'bar')
self.assertEqual(value[2], 'baz')
self.assertEqual(value[0], "foo")
self.assertEqual(value[1], "bar")
self.assertEqual(value[2], "baz")
def test_multiple_values_separated_by_commas(self):
value = mod.parse_list('foo,bar,baz')
value = mod.parse_list("foo,bar,baz")
self.assertEqual(len(value), 3)
self.assertEqual(value[0], 'foo')
self.assertEqual(value[1], 'bar')
self.assertEqual(value[2], 'baz')
self.assertEqual(value[0], "foo")
self.assertEqual(value[1], "bar")
self.assertEqual(value[2], "baz")
def test_multiple_values_separated_by_whitespace_and_commas(self):
value = mod.parse_list(' foo, bar baz')
value = mod.parse_list(" foo, bar baz")
self.assertEqual(len(value), 3)
self.assertEqual(value[0], 'foo')
self.assertEqual(value[1], 'bar')
self.assertEqual(value[2], 'baz')
self.assertEqual(value[0], "foo")
self.assertEqual(value[1], "bar")
self.assertEqual(value[2], "baz")
def test_multiple_values_separated_by_whitespace_and_commas_with_some_quoting(self):
value = mod.parse_list("""
value = mod.parse_list(
"""
foo
"C:\\some path\\with spaces\\and, a comma",
baz
""")
"""
)
self.assertEqual(len(value), 3)
self.assertEqual(value[0], 'foo')
self.assertEqual(value[1], 'C:\\some path\\with spaces\\and, a comma')
self.assertEqual(value[2], 'baz')
self.assertEqual(value[0], "foo")
self.assertEqual(value[1], "C:\\some path\\with spaces\\and, a comma")
self.assertEqual(value[2], "baz")
def test_multiple_values_separated_by_whitespace_and_commas_with_single_quotes(self):
value = mod.parse_list("""
def test_multiple_values_separated_by_whitespace_and_commas_with_single_quotes(
self,
):
value = mod.parse_list(
"""
foo
'C:\\some path\\with spaces\\and, a comma',
baz
""")
"""
)
self.assertEqual(len(value), 3)
self.assertEqual(value[0], 'foo')
self.assertEqual(value[1], 'C:\\some path\\with spaces\\and, a comma')
self.assertEqual(value[2], 'baz')
self.assertEqual(value[0], "foo")
self.assertEqual(value[1], "C:\\some path\\with spaces\\and, a comma")
self.assertEqual(value[2], "baz")
class TestMakeTitle(TestCase):
def test_basic(self):
text = mod.make_title('foo_bar')
text = mod.make_title("foo_bar")
self.assertEqual(text, "Foo Bar")
class TestMakeFullName(TestCase):
def test_basic(self):
name = mod.make_full_name('Fred', '', 'Flintstone', '')
self.assertEqual(name, 'Fred Flintstone')
name = mod.make_full_name("Fred", "", "Flintstone", "")
self.assertEqual(name, "Fred Flintstone")
class TestProgressLoop(TestCase):
@ -278,12 +296,10 @@ class TestProgressLoop(TestCase):
pass
# with progress
mod.progress_loop(act, [1, 2, 3], ProgressBase,
message="whatever")
mod.progress_loop(act, [1, 2, 3], ProgressBase, message="whatever")
# without progress
mod.progress_loop(act, [1, 2, 3], None,
message="whatever")
mod.progress_loop(act, [1, 2, 3], None, message="whatever")
class TestResourcePath(TestCase):
@ -291,11 +307,13 @@ class TestResourcePath(TestCase):
def test_basic(self):
# package spec is resolved to path
path = mod.resource_path('wuttjamaican:util.py')
self.assertTrue(path.endswith('wuttjamaican/util.py'))
path = mod.resource_path("wuttjamaican:util.py")
self.assertTrue(path.endswith("wuttjamaican/util.py"))
# absolute path returned as-is
self.assertEqual(mod.resource_path('/tmp/doesnotexist.txt'), '/tmp/doesnotexist.txt')
self.assertEqual(
mod.resource_path("/tmp/doesnotexist.txt"), "/tmp/doesnotexist.txt"
)
def test_basic_pre_python_3_9(self):
@ -310,20 +328,22 @@ class TestResourcePath(TestCase):
orig_import = __import__
def mock_import(name, globals=None, locals=None, fromlist=(), level=0):
if name == 'importlib.resources':
if name == "importlib.resources":
raise ImportError
if name == 'importlib_resources':
if name == "importlib_resources":
return MagicMock(files=files, as_file=as_file)
return orig_import(name, globals, locals, fromlist, level)
with patch('builtins.__import__', side_effect=mock_import):
with patch("builtins.__import__", side_effect=mock_import):
# package spec is resolved to path
path = mod.resource_path('wuttjamaican:util.py')
self.assertTrue(path.endswith('wuttjamaican/util.py'))
path = mod.resource_path("wuttjamaican:util.py")
self.assertTrue(path.endswith("wuttjamaican/util.py"))
# absolute path returned as-is
self.assertEqual(mod.resource_path('/tmp/doesnotexist.txt'), '/tmp/doesnotexist.txt')
self.assertEqual(
mod.resource_path("/tmp/doesnotexist.txt"), "/tmp/doesnotexist.txt"
)
class TestSimpleError(TestCase):