diff --git a/evennia/accounts/migrations/0009_auto_20191025_0831.py b/evennia/accounts/migrations/0009_auto_20191025_0831.py index 42500ae25b..f61e9e8931 100644 --- a/evennia/accounts/migrations/0009_auto_20191025_0831.py +++ b/evennia/accounts/migrations/0009_auto_20191025_0831.py @@ -5,19 +5,23 @@ from django.db import migrations, models class Migration(migrations.Migration): - dependencies = [ - ('accounts', '0008_auto_20190128_1820'), - ] + dependencies = [("accounts", "0008_auto_20190128_1820")] operations = [ migrations.AlterField( - model_name='accountdb', - name='db_typeclass_path', - field=models.CharField(db_index=True, help_text="this defines what 'type' of entity this is. This variable holds a Python path to a module with a valid Evennia Typeclass.", max_length=255, null=True, verbose_name='typeclass'), + model_name="accountdb", + name="db_typeclass_path", + field=models.CharField( + db_index=True, + help_text="this defines what 'type' of entity this is. This variable holds a Python path to a module with a valid Evennia Typeclass.", + max_length=255, + null=True, + verbose_name="typeclass", + ), ), migrations.AlterField( - model_name='accountdb', - name='last_name', - field=models.CharField(blank=True, max_length=150, verbose_name='last name'), + model_name="accountdb", + name="last_name", + field=models.CharField(blank=True, max_length=150, verbose_name="last name"), ), ] diff --git a/evennia/comms/migrations/0018_auto_20191025_0831.py b/evennia/comms/migrations/0018_auto_20191025_0831.py index e73a6ed067..42a67798f1 100644 --- a/evennia/comms/migrations/0018_auto_20191025_0831.py +++ b/evennia/comms/migrations/0018_auto_20191025_0831.py @@ -5,14 +5,18 @@ from django.db import migrations, models class Migration(migrations.Migration): - dependencies = [ - ('comms', '0017_auto_20190128_1820'), - ] + dependencies = [("comms", "0017_auto_20190128_1820")] operations = [ migrations.AlterField( - model_name='channeldb', - name='db_typeclass_path', - field=models.CharField(db_index=True, help_text="this defines what 'type' of entity this is. This variable holds a Python path to a module with a valid Evennia Typeclass.", max_length=255, null=True, verbose_name='typeclass'), - ), + model_name="channeldb", + name="db_typeclass_path", + field=models.CharField( + db_index=True, + help_text="this defines what 'type' of entity this is. This variable holds a Python path to a module with a valid Evennia Typeclass.", + max_length=255, + null=True, + verbose_name="typeclass", + ), + ) ] diff --git a/evennia/objects/migrations/0011_auto_20191025_0831.py b/evennia/objects/migrations/0011_auto_20191025_0831.py index f946acaad8..98d61b8797 100644 --- a/evennia/objects/migrations/0011_auto_20191025_0831.py +++ b/evennia/objects/migrations/0011_auto_20191025_0831.py @@ -7,19 +7,35 @@ import re class Migration(migrations.Migration): - dependencies = [ - ('objects', '0010_auto_20190128_1820'), - ] + dependencies = [("objects", "0010_auto_20190128_1820")] operations = [ migrations.AlterField( - model_name='objectdb', - name='db_sessid', - field=models.CharField(help_text='csv list of session ids of connected Account, if any.', max_length=32, null=True, validators=[django.core.validators.RegexValidator(re.compile('^\\d+(?:,\\d+)*\\Z'), code='invalid', message='Enter only digits separated by commas.')], verbose_name='session id'), + model_name="objectdb", + name="db_sessid", + field=models.CharField( + help_text="csv list of session ids of connected Account, if any.", + max_length=32, + null=True, + validators=[ + django.core.validators.RegexValidator( + re.compile("^\\d+(?:,\\d+)*\\Z"), + code="invalid", + message="Enter only digits separated by commas.", + ) + ], + verbose_name="session id", + ), ), migrations.AlterField( - model_name='objectdb', - name='db_typeclass_path', - field=models.CharField(db_index=True, help_text="this defines what 'type' of entity this is. This variable holds a Python path to a module with a valid Evennia Typeclass.", max_length=255, null=True, verbose_name='typeclass'), + model_name="objectdb", + name="db_typeclass_path", + field=models.CharField( + db_index=True, + help_text="this defines what 'type' of entity this is. This variable holds a Python path to a module with a valid Evennia Typeclass.", + max_length=255, + null=True, + verbose_name="typeclass", + ), ), ] diff --git a/evennia/scripts/migrations/0013_auto_20191025_0831.py b/evennia/scripts/migrations/0013_auto_20191025_0831.py index 9dca21d75a..be687c8fd2 100644 --- a/evennia/scripts/migrations/0013_auto_20191025_0831.py +++ b/evennia/scripts/migrations/0013_auto_20191025_0831.py @@ -5,14 +5,18 @@ from django.db import migrations, models class Migration(migrations.Migration): - dependencies = [ - ('scripts', '0012_auto_20190128_1820'), - ] + dependencies = [("scripts", "0012_auto_20190128_1820")] operations = [ migrations.AlterField( - model_name='scriptdb', - name='db_typeclass_path', - field=models.CharField(db_index=True, help_text="this defines what 'type' of entity this is. This variable holds a Python path to a module with a valid Evennia Typeclass.", max_length=255, null=True, verbose_name='typeclass'), - ), + model_name="scriptdb", + name="db_typeclass_path", + field=models.CharField( + db_index=True, + help_text="this defines what 'type' of entity this is. This variable holds a Python path to a module with a valid Evennia Typeclass.", + max_length=255, + null=True, + verbose_name="typeclass", + ), + ) ] diff --git a/evennia/typeclasses/migrations/0013_auto_20191015_1922.py b/evennia/typeclasses/migrations/0013_auto_20191015_1922.py index 83578e1694..6eff90077d 100644 --- a/evennia/typeclasses/migrations/0013_auto_20191015_1922.py +++ b/evennia/typeclasses/migrations/0013_auto_20191015_1922.py @@ -5,14 +5,19 @@ from django.db import migrations, models class Migration(migrations.Migration): - dependencies = [ - ('typeclasses', '0012_attrs_to_picklev4_may_be_slow'), - ] + dependencies = [("typeclasses", "0012_attrs_to_picklev4_may_be_slow")] operations = [ migrations.AlterField( - model_name='tag', - name='db_tagtype', - field=models.CharField(blank=True, db_index=True, help_text='overall type of Tag', max_length=16, null=True, verbose_name='tagtype'), - ), + model_name="tag", + name="db_tagtype", + field=models.CharField( + blank=True, + db_index=True, + help_text="overall type of Tag", + max_length=16, + null=True, + verbose_name="tagtype", + ), + ) ] diff --git a/evennia/typeclasses/tags.py b/evennia/typeclasses/tags.py index 313a2a7a97..7dac017777 100644 --- a/evennia/typeclasses/tags.py +++ b/evennia/typeclasses/tags.py @@ -67,7 +67,12 @@ class Tag(models.Model): ) # this is None, alias or permission db_tagtype = models.CharField( - "tagtype", max_length=16, null=True, blank=True, help_text="overall type of Tag", db_index=True + "tagtype", + max_length=16, + null=True, + blank=True, + help_text="overall type of Tag", + db_index=True, ) class Meta(object): diff --git a/evennia/utils/tests/test_eveditor.py b/evennia/utils/tests/test_eveditor.py index 250e05189e..730fcde8a3 100644 --- a/evennia/utils/tests/test_eveditor.py +++ b/evennia/utils/tests/test_eveditor.py @@ -168,9 +168,9 @@ class TestEvEditor(CommandTest): ) self.call( eveditor.CmdLineInput(), - "First test \"line\".", - raw_string="First test \"line\".", - msg="01First test \"line\" .", + 'First test "line".', + raw_string='First test "line".', + msg='01First test "line" .', ) self.call( eveditor.CmdLineInput(), @@ -178,7 +178,9 @@ class TestEvEditor(CommandTest): raw_string="Second 'line'.", msg="02Second 'line' .", ) - self.assertEqual(self.char1.ndb._eveditor.get_buffer(), "First test \"line\".\nSecond 'line'.") + self.assertEqual( + self.char1.ndb._eveditor.get_buffer(), "First test \"line\".\nSecond 'line'." + ) self.call( eveditor.CmdEditorGroup(), "", @@ -195,21 +197,9 @@ class TestEvEditor(CommandTest): cmdstring=":", msg="Line Editor []\n01\n[l:01 w:000 c:0000](:h for help)", ) - self.call( - eveditor.CmdLineInput(), "line 1.", - raw_string="line 1.", - msg="01line 1.", - ) - self.call( - eveditor.CmdLineInput(), "line 2.", - raw_string="line 2.", - msg="02line 2.", - ) - self.call( - eveditor.CmdLineInput(), "line 3.", - raw_string="line 3.", - msg="03line 3.", - ) + self.call(eveditor.CmdLineInput(), "line 1.", raw_string="line 1.", msg="01line 1.") + self.call(eveditor.CmdLineInput(), "line 2.", raw_string="line 2.", msg="02line 2.") + self.call(eveditor.CmdLineInput(), "line 3.", raw_string="line 3.", msg="03line 3.") self.call( eveditor.CmdEditorGroup(), "2:3", @@ -222,16 +212,14 @@ class TestEvEditor(CommandTest): cmdstring=":s", msg="Search-replaced line -> LINE for lines 1-2.", ) - self.assertEqual(self.char1.ndb._eveditor.get_buffer(), - "LINE 1.\nLINE 2.\nline 3.") + self.assertEqual(self.char1.ndb._eveditor.get_buffer(), "LINE 1.\nLINE 2.\nline 3.") self.call( eveditor.CmdEditorGroup(), "line MINE", cmdstring=":s", msg="Search-replaced line -> MINE for lines 1-3.", ) - self.assertEqual(self.char1.ndb._eveditor.get_buffer(), - "LINE 1.\nLINE 2.\nMINE 3.") + self.assertEqual(self.char1.ndb._eveditor.get_buffer(), "LINE 1.\nLINE 2.\nMINE 3.") def test_eveditor_COLON_DD(self): eveditor.EvEditor(self.char1) @@ -241,26 +229,11 @@ class TestEvEditor(CommandTest): cmdstring=":", msg="Line Editor []\n01\n[l:01 w:000 c:0000](:h for help)", ) + self.call(eveditor.CmdLineInput(), "line 1.", raw_string="line 1.", msg="01line 1.") + self.call(eveditor.CmdLineInput(), "line 2.", raw_string="line 2.", msg="02line 2.") + self.call(eveditor.CmdLineInput(), "line 3.", raw_string="line 3.", msg="03line 3.") self.call( - eveditor.CmdLineInput(), "line 1.", - raw_string="line 1.", - msg="01line 1.", - ) - self.call( - eveditor.CmdLineInput(), "line 2.", - raw_string="line 2.", - msg="02line 2.", - ) - self.call( - eveditor.CmdLineInput(), "line 3.", - raw_string="line 3.", - msg="03line 3.", - ) - self.call( - eveditor.CmdEditorGroup(), - "", - cmdstring=":DD", - msg="Cleared 3 lines from buffer.", + eveditor.CmdEditorGroup(), "", cmdstring=":DD", msg="Cleared 3 lines from buffer." ) self.assertEqual(self.char1.ndb._eveditor.get_buffer(), "") @@ -272,17 +245,8 @@ class TestEvEditor(CommandTest): cmdstring=":", msg="Line Editor []\n01\n[l:01 w:000 c:0000](:h for help)", ) - self.call( - eveditor.CmdLineInput(), "line 1", - raw_string="line 1", - msg="01line 1", - ) - self.call( - eveditor.CmdEditorGroup(), - "1:2", - cmdstring=":f", - msg="Flood filled lines 1-2.", - ) + self.call(eveditor.CmdLineInput(), "line 1", raw_string="line 1", msg="01line 1") + self.call(eveditor.CmdEditorGroup(), "1:2", cmdstring=":f", msg="Flood filled lines 1-2.") self.assertEqual(self.char1.ndb._eveditor.get_buffer(), "line 1") def test_eveditor_COLON_J(self): @@ -293,44 +257,13 @@ class TestEvEditor(CommandTest): cmdstring=":", msg="Line Editor []\n01\n[l:01 w:000 c:0000](:h for help)", ) - self.call( - eveditor.CmdLineInput(), "line 1", - raw_string="line 1", - msg="01line 1", - ) - self.call( - eveditor.CmdLineInput(), "l 2", - raw_string="l 2", - msg="02l 2", - ) - self.call( - eveditor.CmdLineInput(), "l 3", - raw_string="l 3", - msg="03l 3", - ) - self.call( - eveditor.CmdLineInput(), "l 4", - raw_string="l 4", - msg="04l 4", - ) - self.call( - eveditor.CmdEditorGroup(), - "2 r", - cmdstring=":j", - msg="Right-justified line 2.", - ) - self.call( - eveditor.CmdEditorGroup(), - "3 c", - cmdstring=":j", - msg="Center-justified line 3.", - ) - self.call( - eveditor.CmdEditorGroup(), - "4 f", - cmdstring=":j", - msg="Full-justified line 4.", - ) + self.call(eveditor.CmdLineInput(), "line 1", raw_string="line 1", msg="01line 1") + self.call(eveditor.CmdLineInput(), "l 2", raw_string="l 2", msg="02l 2") + self.call(eveditor.CmdLineInput(), "l 3", raw_string="l 3", msg="03l 3") + self.call(eveditor.CmdLineInput(), "l 4", raw_string="l 4", msg="04l 4") + self.call(eveditor.CmdEditorGroup(), "2 r", cmdstring=":j", msg="Right-justified line 2.") + self.call(eveditor.CmdEditorGroup(), "3 c", cmdstring=":j", msg="Center-justified line 3.") + self.call(eveditor.CmdEditorGroup(), "4 f", cmdstring=":j", msg="Full-justified line 4.") l1, l2, l3, l4 = tuple(self.char1.ndb._eveditor.get_buffer().split("\n")) self.assertEqual(l1, "line 1") self.assertEqual(l2, " " * 75 + "l 2") @@ -345,11 +278,7 @@ class TestEvEditor(CommandTest): cmdstring=":", msg="Line Editor []\n01\n[l:01 w:000 c:0000](:h for help)", ) - self.call( - eveditor.CmdLineInput(), "line 1.", - raw_string="line 1.", - msg="01line 1.", - ) + self.call(eveditor.CmdLineInput(), "line 1.", raw_string="line 1.", msg="01line 1.") self.call( eveditor.CmdEditorGroup(), "", diff --git a/evennia/utils/tests/test_text2html.py b/evennia/utils/tests/test_text2html.py index 439cd96c43..f6466466e1 100644 --- a/evennia/utils/tests/test_text2html.py +++ b/evennia/utils/tests/test_text2html.py @@ -7,19 +7,28 @@ import mock class TestText2Html(TestCase): - def test_re_color(self): parser = text2html.HTML_PARSER self.assertEqual("foo", parser.re_color("foo")) self.assertEqual( - "redfoo", - parser.re_color(ansi.ANSI_UNHILITE + ansi.ANSI_RED + "red" + ansi.ANSI_NORMAL + "foo")) + 'redfoo', + parser.re_color(ansi.ANSI_UNHILITE + ansi.ANSI_RED + "red" + ansi.ANSI_NORMAL + "foo"), + ) self.assertEqual( - "redfoo", - parser.re_color(ansi.ANSI_BACK_RED + "red" + ansi.ANSI_NORMAL + "foo")) + 'redfoo', + parser.re_color(ansi.ANSI_BACK_RED + "red" + ansi.ANSI_NORMAL + "foo"), + ) self.assertEqual( - "redfoo", - parser.re_color(ansi.ANSI_BACK_RED + ansi.ANSI_UNHILITE + ansi.ANSI_GREEN + "red" + ansi.ANSI_NORMAL + "foo")) + 'redfoo', + parser.re_color( + ansi.ANSI_BACK_RED + + ansi.ANSI_UNHILITE + + ansi.ANSI_GREEN + + "red" + + ansi.ANSI_NORMAL + + "foo" + ), + ) @unittest.skip("parser issues") def test_re_bold(self): @@ -28,41 +37,53 @@ class TestText2Html(TestCase): self.assertEqual( # "a redfoo", # TODO: why not? "a redfoo", - parser.re_bold( - "a " + ansi.ANSI_HILITE + "red" + ansi.ANSI_UNHILITE + "foo")) + parser.re_bold("a " + ansi.ANSI_HILITE + "red" + ansi.ANSI_UNHILITE + "foo"), + ) @unittest.skip("parser issues") def test_re_underline(self): parser = text2html.HTML_PARSER self.assertEqual("foo", parser.re_underline("foo")) self.assertEqual( - "a red" + ansi.ANSI_NORMAL + "foo", + 'a red' + ansi.ANSI_NORMAL + "foo", parser.re_underline( - "a " + ansi.ANSI_UNDERLINE + "red" + "a " + + ansi.ANSI_UNDERLINE + + "red" + ansi.ANSI_NORMAL # TODO: why does it keep it? - + "foo")) + + "foo" + ), + ) @unittest.skip("parser issues") def test_re_blinking(self): parser = text2html.HTML_PARSER self.assertEqual("foo", parser.re_blinking("foo")) self.assertEqual( - "a red" + ansi.ANSI_NORMAL + "foo", + 'a red' + ansi.ANSI_NORMAL + "foo", parser.re_blinking( - "a " + ansi.ANSI_BLINK + "red" + "a " + + ansi.ANSI_BLINK + + "red" + ansi.ANSI_NORMAL # TODO: why does it keep it? - + "foo")) + + "foo" + ), + ) @unittest.skip("parser issues") def test_re_inversing(self): parser = text2html.HTML_PARSER self.assertEqual("foo", parser.re_inversing("foo")) self.assertEqual( - "a red" + ansi.ANSI_NORMAL + "foo", + 'a red' + ansi.ANSI_NORMAL + "foo", parser.re_inversing( - "a " + ansi.ANSI_INVERSE + "red" + "a " + + ansi.ANSI_INVERSE + + "red" + ansi.ANSI_NORMAL # TODO: why does it keep it? - + "foo")) + + "foo" + ), + ) @unittest.skip("parser issues") def test_remove_bells(self): @@ -71,38 +92,40 @@ class TestText2Html(TestCase): self.assertEqual( "a red" + ansi.ANSI_NORMAL + "foo", parser.remove_bells( - "a " + ansi.ANSI_BEEP + "red" + "a " + + ansi.ANSI_BEEP + + "red" + ansi.ANSI_NORMAL # TODO: why does it keep it? - + "foo")) + + "foo" + ), + ) def test_remove_backspaces(self): parser = text2html.HTML_PARSER self.assertEqual("foo", parser.remove_backspaces("foo")) - self.assertEqual("redfoo", - parser.remove_backspaces("a\010redfoo")) + self.assertEqual("redfoo", parser.remove_backspaces("a\010redfoo")) def test_convert_linebreaks(self): parser = text2html.HTML_PARSER self.assertEqual("foo", parser.convert_linebreaks("foo")) - self.assertEqual( - "a
redfoo
", - parser.convert_linebreaks("a\n redfoo\n")) + self.assertEqual("a
redfoo
", parser.convert_linebreaks("a\n redfoo\n")) @unittest.skip("parser issues") def test_convert_urls(self): parser = text2html.HTML_PARSER self.assertEqual("foo", parser.convert_urls("foo")) self.assertEqual( - "a http://redfoo runs", - parser.convert_urls("a http://redfoo runs")) - # TODO: doesn't URL encode correctly + 'a http://redfoo runs', + parser.convert_urls("a http://redfoo runs"), + ) + # TODO: doesn't URL encode correctly def test_re_double_space(self): parser = text2html.HTML_PARSER self.assertEqual("foo", parser.re_double_space("foo")) self.assertEqual( - "a  red    foo", - parser.re_double_space("a red foo")) + "a  red    foo", parser.re_double_space("a red foo") + ) def test_sub_mxp_links(self): parser = text2html.HTML_PARSER @@ -112,63 +135,43 @@ class TestText2Html(TestCase): r"""text""", - parser.sub_mxp_links(mocked_match)) + parser.sub_mxp_links(mocked_match), + ) def test_sub_text(self): parser = text2html.HTML_PARSER mocked_match = mock.Mock() - mocked_match.groupdict.return_value = { - "htmlchars": "foo" - } - self.assertEqual( - "foo", - parser.sub_text(mocked_match)) - mocked_match.groupdict.return_value = { - "htmlchars": "", - "lineend": "foo", - } - self.assertEqual( - "
", - parser.sub_text(mocked_match)) - mocked_match.groupdict.return_value = { - "htmlchars": "", - "lineend": "", - "firstspace": "foo" - } - self.assertEqual( - "  ", - parser.sub_text(mocked_match)) + mocked_match.groupdict.return_value = {"htmlchars": "foo"} + self.assertEqual("foo", parser.sub_text(mocked_match)) + mocked_match.groupdict.return_value = {"htmlchars": "", "lineend": "foo"} + self.assertEqual("
", parser.sub_text(mocked_match)) + mocked_match.groupdict.return_value = {"htmlchars": "", "lineend": "", "firstspace": "foo"} + self.assertEqual("  ", parser.sub_text(mocked_match)) parser.tabstop = 2 mocked_match.groupdict.return_value = { "htmlchars": "", "lineend": "", "firstspace": "", - "space": "\t" + "space": "\t", } - self.assertEqual( - "   ", - parser.sub_text(mocked_match)) + self.assertEqual("   ", parser.sub_text(mocked_match)) mocked_match.groupdict.return_value = { "htmlchars": "", "lineend": "", "firstspace": "", "space": " ", - "spacestart": " " + "spacestart": " ", } mocked_match.group.return_value = " \t " - self.assertEqual( - "    ", - parser.sub_text(mocked_match)) + self.assertEqual("    ", parser.sub_text(mocked_match)) mocked_match.groupdict.return_value = { "htmlchars": "", "lineend": "", "firstspace": "", "space": "", - "spacestart": "" + "spacestart": "", } - self.assertEqual( - None, - parser.sub_text(mocked_match)) + self.assertEqual(None, parser.sub_text(mocked_match)) def test_parse_html(self): self.assertEqual("foo", text2html.parse_html("foo")) @@ -176,12 +179,24 @@ class TestText2Html(TestCase): self.assertEqual( """Hello World!!""", text2html.parse_html( - ansi.ANSI_BLINK + ansi.ANSI_BACK_CYAN + "Hello " + ansi.ANSI_NORMAL - + ansi.ANSI_UNDERLINE + ansi.ANSI_RED + "W" - + ansi.ANSI_GREEN + "o" - + ansi.ANSI_YELLOW + "r" - + ansi.ANSI_BLUE + "l" - + ansi.ANSI_MAGENTA + "d" - + ansi.ANSI_CYAN + "!" - + ansi.ANSI_BACK_GREEN + "!")) - + ansi.ANSI_BLINK + + ansi.ANSI_BACK_CYAN + + "Hello " + + ansi.ANSI_NORMAL + + ansi.ANSI_UNDERLINE + + ansi.ANSI_RED + + "W" + + ansi.ANSI_GREEN + + "o" + + ansi.ANSI_YELLOW + + "r" + + ansi.ANSI_BLUE + + "l" + + ansi.ANSI_MAGENTA + + "d" + + ansi.ANSI_CYAN + + "!" + + ansi.ANSI_BACK_GREEN + + "!" + ), + ) diff --git a/evennia/utils/tests/test_validatorfuncs.py b/evennia/utils/tests/test_validatorfuncs.py index 0c1b87e40e..54823bc4ee 100644 --- a/evennia/utils/tests/test_validatorfuncs.py +++ b/evennia/utils/tests/test_validatorfuncs.py @@ -8,20 +8,19 @@ import pytz class TestValidatorFuncs(TestCase): - def test_text_ok(self): - for val in [None, -123, 'abc', 1.234, {1:True, 2:False}, ['a', 1]]: + for val in [None, -123, "abc", 1.234, {1: True, 2: False}, ["a", 1]]: self.assertEqual(str(val), validatorfuncs.text(val)) - @mock.patch('builtins.str') + @mock.patch("builtins.str") def test_text_raises_ValueError(self, mocked_str): mocked_str.side_effect = Exception with self.assertRaises(ValueError): validatorfuncs.text(None) def test_color_ok(self): - for color in ['r', 'g', 'b', 'H', 'R', 'M', '^']: - self.assertEqual(color, validatorfuncs.color(color)) + for color in ["r", "g", "b", "H", "R", "M", "^"]: + self.assertEqual(color, validatorfuncs.color(color)) def test_color_falsy_raises_ValueError(self): for color in [None, (), [], False, True, {}]: @@ -29,126 +28,125 @@ class TestValidatorFuncs(TestCase): validatorfuncs.color(color) def test_datetime_ok(self): - for dt in ['Oct 12 1:00 1492', 'Jan 2 12:00 2020', 'Dec 31 00:00 2018']: + for dt in ["Oct 12 1:00 1492", "Jan 2 12:00 2020", "Dec 31 00:00 2018"]: self.assertTrue( - isinstance(validatorfuncs.datetime(dt, from_tz=pytz.UTC), - datetime.datetime)) + isinstance(validatorfuncs.datetime(dt, from_tz=pytz.UTC), datetime.datetime) + ) def test_datetime_raises_ValueError(self): - for dt in ['', 'January 1, 2019', '1/1/2019', 'Jan 1 2019']: + for dt in ["", "January 1, 2019", "1/1/2019", "Jan 1 2019"]: with self.assertRaises(ValueError): validatorfuncs.datetime(dt) def test_duration_ok(self): - for d in ['1d', '2w', '3h', '4s', '5m', '6y']: - self.assertTrue( - isinstance(validatorfuncs.duration(d), datetime.timedelta)) + for d in ["1d", "2w", "3h", "4s", "5m", "6y"]: + self.assertTrue(isinstance(validatorfuncs.duration(d), datetime.timedelta)) self.assertEqual( - datetime.timedelta(1+6*365, 2, 0, 0, 3, 4, 5), - validatorfuncs.duration('1d 2s 3m 4h 5w 6y')) + datetime.timedelta(1 + 6 * 365, 2, 0, 0, 3, 4, 5), + validatorfuncs.duration("1d 2s 3m 4h 5w 6y"), + ) # values may be duplicated self.assertEqual( - datetime.timedelta((1+7)+(6+12)*365, 2+8, 0, 0, 3+9, 4+10, 5+11), - validatorfuncs.duration('1d 2s 3m 4h 5w 6y 7d 8s 9m 10h 11w 12y')) + datetime.timedelta((1 + 7) + (6 + 12) * 365, 2 + 8, 0, 0, 3 + 9, 4 + 10, 5 + 11), + validatorfuncs.duration("1d 2s 3m 4h 5w 6y 7d 8s 9m 10h 11w 12y"), + ) def test_duration_raises_ValueError(self): - for d in ['', '1', '5days', '1Week']: + for d in ["", "1", "5days", "1Week"]: with self.assertRaises(ValueError): validatorfuncs.duration(d) def test_future_ok(self): year = int(datetime.datetime.utcnow().strftime("%Y")) - for f in [f'Jan 2 12:00 {year+1}', f'Dec 31 00:00 {year+1}']: + for f in [f"Jan 2 12:00 {year+1}", f"Dec 31 00:00 {year+1}"]: self.assertTrue( - isinstance(validatorfuncs.future(f, from_tz=pytz.UTC), - datetime.datetime)) + isinstance(validatorfuncs.future(f, from_tz=pytz.UTC), datetime.datetime) + ) def test_future_raises_ValueError(self): year = int(datetime.datetime.utcnow().strftime("%Y")) - for f in [f'Jan 2 12:00 {year-1}', f'Dec 31 00:00 {year-1}']: + for f in [f"Jan 2 12:00 {year-1}", f"Dec 31 00:00 {year-1}"]: with self.assertRaises(ValueError): validatorfuncs.future(f, from_tz=pytz.UTC) def test_signed_integer_ok(self): - for si in ['123', '4567890', '001', '-123', '-45', '0']: - self.assertEqual(int(si), validatorfuncs.signed_integer(si)) + for si in ["123", "4567890", "001", "-123", "-45", "0"]: + self.assertEqual(int(si), validatorfuncs.signed_integer(si)) - @mock.patch('builtins.int') + @mock.patch("builtins.int") def test_signed_integer_raises_ValueError(self, mocked_int): - for si in ['', '000', 'abc']: + for si in ["", "000", "abc"]: mocked_int.side_effect = ValueError with self.assertRaises(ValueError): validatorfuncs.signed_integer(si) def test_positive_integer_ok(self): - for pi in ['123', '4567890', '001']: - self.assertEqual(int(pi), validatorfuncs.positive_integer(pi)) + for pi in ["123", "4567890", "001"]: + self.assertEqual(int(pi), validatorfuncs.positive_integer(pi)) - @mock.patch('builtins.int') + @mock.patch("builtins.int") def test_positive_integer_raises_ValueError(self, mocked_int): mocked_int.return_value = -1 with self.assertRaises(ValueError): validatorfuncs.positive_integer(str(-1)) - for pi in ['', '000', 'abc', '-1']: + for pi in ["", "000", "abc", "-1"]: mocked_int.side_effect = ValueError with self.assertRaises(ValueError): validatorfuncs.positive_integer(pi) def test_unsigned_integer_ok(self): - for ui in ['123', '4567890', '001', '0']: - self.assertEqual(int(ui), validatorfuncs.unsigned_integer(ui)) + for ui in ["123", "4567890", "001", "0"]: + self.assertEqual(int(ui), validatorfuncs.unsigned_integer(ui)) - @mock.patch('builtins.int') + @mock.patch("builtins.int") def test_unsigned_integer_raises_ValueError(self, mocked_int): mocked_int.return_value = -1 with self.assertRaises(ValueError): validatorfuncs.unsigned_integer(str(-1)) - for ui in ['', '000', 'abc', '-1', '0']: + for ui in ["", "000", "abc", "-1", "0"]: mocked_int.side_effect = ValueError with self.assertRaises(ValueError): validatorfuncs.unsigned_integer(ui) def test_boolean(self): - for b in ['true', '1', 'on', 'ENABLED']: + for b in ["true", "1", "on", "ENABLED"]: self.assertTrue(validatorfuncs.boolean(b)) - for b in ['FalSe', '0', 'oFF', 'disabled']: + for b in ["FalSe", "0", "oFF", "disabled"]: self.assertFalse(validatorfuncs.boolean(b)) def test_boolean_raises_ValueError(self): - for b in ['', None, 1, 0, True, False, [None], {True:True}]: + for b in ["", None, 1, 0, True, False, [None], {True: True}]: with self.assertRaises(ValueError): validatorfuncs.boolean(b) def test_timezone_ok(self): - for tz in ['America/Chicago', 'GMT', 'UTC']: + for tz in ["America/Chicago", "GMT", "UTC"]: self.assertEqual(tz, validatorfuncs.timezone(tz).zone) def test_timezone_raises_ValueError(self): - for tz in ['America', None, '', 'Mars', 'DT']: + for tz in ["America", None, "", "Mars", "DT"]: with self.assertRaises(ValueError): validatorfuncs.timezone(tz) def test_email_ok(self): - for e in ['a@a.aa', 'zeus@olympus.net']: + for e in ["a@a.aa", "zeus@olympus.net"]: self.assertEqual(e, validatorfuncs.email(e)) def test_email_raises_ValueError(self): - for e in ['', None, ['abc@abc.com'], 123]: + for e in ["", None, ["abc@abc.com"], 123]: with self.assertRaises(ValueError): validatorfuncs.email(e) def test_lock_ok(self): - for l in ['do:true;look:no', 'a:t']: + for l in ["do:true;look:no", "a:t"]: self.assertEqual(l, validatorfuncs.lock(l)) def test_lock_raises_ValueError(self): - for l in [';;;', '', ':', ':::', ';:;:', 'x:', ':y']: + for l in [";;;", "", ":", ":::", ";:;:", "x:", ":y"]: with self.assertRaises(ValueError): validatorfuncs.lock(l) with self.assertRaises(ValueError): - validatorfuncs.lock('view:', - access_options=()) + validatorfuncs.lock("view:", access_options=()) with self.assertRaises(ValueError): - validatorfuncs.lock('view:', - access_options=('look')) + validatorfuncs.lock("view:", access_options=("look"))