diff options
| author | Simon Charette <charette.s@gmail.com> | 2017-01-19 09:48:01 -0500 |
|---|---|---|
| committer | Simon Charette <charette.s@gmail.com> | 2017-01-19 11:31:07 -0500 |
| commit | 9695b149820cff31cfa48973efe4256c80811e87 (patch) | |
| tree | bf73b5301788ac35873b208b15c512fb585708b9 /tests | |
| parent | 41e0033caf1267edda2b780ae50a3881c3de94ef (diff) | |
Refs #23919 -- Removed str() conversion of type and method __name__.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/apps/tests.py | 16 | ||||
| -rw-r--r-- | tests/auth_tests/test_hashers.py | 2 | ||||
| -rw-r--r-- | tests/invalid_models_tests/test_relative_fields.py | 4 | ||||
| -rw-r--r-- | tests/migrations/test_state.py | 2 | ||||
| -rw-r--r-- | tests/migrations/test_writer.py | 10 | ||||
| -rw-r--r-- | tests/model_forms/tests.py | 12 | ||||
| -rw-r--r-- | tests/model_inheritance/test_abstract_inheritance.py | 10 | ||||
| -rw-r--r-- | tests/queryset_pickle/tests.py | 3 | ||||
| -rw-r--r-- | tests/servers/tests.py | 2 | ||||
| -rw-r--r-- | tests/validation/test_unique.py | 2 |
10 files changed, 31 insertions, 32 deletions
diff --git a/tests/apps/tests.py b/tests/apps/tests.py index e270662436..0263af897f 100644 --- a/tests/apps/tests.py +++ b/tests/apps/tests.py @@ -197,10 +197,10 @@ class AppsTests(SimpleTestCase): 'app_label': "apps", 'apps': new_apps, } - meta = type(str("Meta"), tuple(), meta_contents) + meta = type("Meta", tuple(), meta_contents) body['Meta'] = meta body['__module__'] = TotallyNormal.__module__ - temp_model = type(str("SouthPonies"), (models.Model,), body) + temp_model = type("SouthPonies", (models.Model,), body) # Make sure it appeared in the right place! self.assertListEqual(list(apps.get_app_config("apps").get_models()), old_models) with self.assertRaises(LookupError): @@ -218,15 +218,15 @@ class AppsTests(SimpleTestCase): } body = {} - body['Meta'] = type(str("Meta"), tuple(), meta_contents) + body['Meta'] = type("Meta", tuple(), meta_contents) body['__module__'] = TotallyNormal.__module__ - type(str("SouthPonies"), (models.Model,), body) + type("SouthPonies", (models.Model,), body) # When __name__ and __module__ match we assume the module # was reloaded and issue a warning. This use-case is # useful for REPL. Refs #23621. body = {} - body['Meta'] = type(str("Meta"), tuple(), meta_contents) + body['Meta'] = type("Meta", tuple(), meta_contents) body['__module__'] = TotallyNormal.__module__ msg = ( "Model 'apps.southponies' was already registered. " @@ -234,15 +234,15 @@ class AppsTests(SimpleTestCase): "most notably with related models." ) with self.assertRaisesMessage(RuntimeWarning, msg): - type(str("SouthPonies"), (models.Model,), body) + type("SouthPonies", (models.Model,), body) # If it doesn't appear to be a reloaded module then we expect # a RuntimeError. body = {} - body['Meta'] = type(str("Meta"), tuple(), meta_contents) + body['Meta'] = type("Meta", tuple(), meta_contents) body['__module__'] = TotallyNormal.__module__ + '.whatever' with self.assertRaisesMessage(RuntimeError, "Conflicting 'southponies' models in application 'apps':"): - type(str("SouthPonies"), (models.Model,), body) + type("SouthPonies", (models.Model,), body) def test_get_containing_app_config_apps_not_ready(self): """ diff --git a/tests/auth_tests/test_hashers.py b/tests/auth_tests/test_hashers.py index 4b6aa8f799..59de85ad9f 100644 --- a/tests/auth_tests/test_hashers.py +++ b/tests/auth_tests/test_hashers.py @@ -429,7 +429,7 @@ class TestUtilsHashPass(SimpleTestCase): self.assertEqual("Hasher 'BasePasswordHasher' doesn't specify a library attribute", str(e.exception)) def test_load_library_importerror(self): - PlainHasher = type(str('PlainHasher'), (BasePasswordHasher,), {'algorithm': 'plain', 'library': 'plain'}) + PlainHasher = type('PlainHasher', (BasePasswordHasher,), {'algorithm': 'plain', 'library': 'plain'}) # Python 3 adds quotes around module name msg = "Couldn't load 'PlainHasher' algorithm library: No module named '?plain'?" with self.assertRaisesRegex(ValueError, msg): diff --git a/tests/invalid_models_tests/test_relative_fields.py b/tests/invalid_models_tests/test_relative_fields.py index 384d1fa03e..db677bd670 100644 --- a/tests/invalid_models_tests/test_relative_fields.py +++ b/tests/invalid_models_tests/test_relative_fields.py @@ -661,7 +661,7 @@ class RelativeFieldTests(SimpleTestCase): pass for invalid_related_name in invalid_related_names: - Child = type(str('Child%s') % str(invalid_related_name), (models.Model,), { + Child = type('Child%s' % invalid_related_name, (models.Model,), { 'parent': models.ForeignKey('Parent', models.CASCADE, related_name=invalid_related_name), '__module__': Parent.__module__, }) @@ -700,7 +700,7 @@ class RelativeFieldTests(SimpleTestCase): pass for related_name in related_names: - Child = type(str('Child%s') % str(related_name), (models.Model,), { + Child = type('Child%s' % related_name, (models.Model,), { 'parent': models.ForeignKey('Parent', models.CASCADE, related_name=related_name), '__module__': Parent.__module__, }) diff --git a/tests/migrations/test_state.py b/tests/migrations/test_state.py index a6b027e079..badd45a5aa 100644 --- a/tests/migrations/test_state.py +++ b/tests/migrations/test_state.py @@ -1058,7 +1058,7 @@ class RelatedModelsTests(SimpleTestCase): 'apps': self.apps, 'proxy': proxy, } - meta = type(str("Meta"), tuple(), meta_contents) + meta = type("Meta", tuple(), meta_contents) if not bases: bases = (models.Model,) body = { diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py index ff5e22ac5e..ab6280856a 100644 --- a/tests/migrations/test_writer.py +++ b/tests/migrations/test_writer.py @@ -542,7 +542,7 @@ class WriterTests(SimpleTestCase): 'verbose_name_plural': 'My models', } - migration = type(str("Migration"), (migrations.Migration,), { + migration = type("Migration", (migrations.Migration,), { "operations": [ migrations.CreateModel("MyModel", tuple(fields.items()), options, (models.Model,)), migrations.CreateModel("MyModel2", tuple(fields.items()), bases=(models.Model,)), @@ -593,7 +593,7 @@ class WriterTests(SimpleTestCase): self.assertEqual(writer.path, expected_path) def test_custom_operation(self): - migration = type(str("Migration"), (migrations.Migration,), { + migration = type("Migration", (migrations.Migration,), { "operations": [ custom_migration_operations.operations.TestOperation(), custom_migration_operations.operations.CreateModel(), @@ -615,7 +615,7 @@ class WriterTests(SimpleTestCase): """ #24155 - Tests ordering of imports. """ - migration = type(str("Migration"), (migrations.Migration,), { + migration = type("Migration", (migrations.Migration,), { "operations": [ migrations.AddField("mymodel", "myfield", models.DateTimeField( default=datetime.datetime(2012, 1, 1, 1, 1, tzinfo=utc), @@ -635,7 +635,7 @@ class WriterTests(SimpleTestCase): """ Test comments at top of file. """ - migration = type(str("Migration"), (migrations.Migration,), { + migration = type("Migration", (migrations.Migration,), { "operations": [] }) dt = datetime.datetime(2015, 7, 31, 4, 40, 0, 0, tzinfo=utc) @@ -655,7 +655,7 @@ class WriterTests(SimpleTestCase): """ django.db.models shouldn't be imported if unused. """ - migration = type(str("Migration"), (migrations.Migration,), { + migration = type("Migration", (migrations.Migration,), { "operations": [ migrations.AlterModelOptions( name='model', diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py index da28fcc7d6..108c917587 100644 --- a/tests/model_forms/tests.py +++ b/tests/model_forms/tests.py @@ -2731,12 +2731,12 @@ class ModelFormInheritanceTests(SimpleTestCase): foo = forms.IntegerField() self.assertEqual(list(ModelForm().fields.keys()), ['name']) - self.assertEqual(list(type(str('NewForm'), (Mixin, Form), {})().fields.keys()), []) - self.assertEqual(list(type(str('NewForm'), (Form2, Mixin, Form), {})().fields.keys()), ['foo']) - self.assertEqual(list(type(str('NewForm'), (Mixin, ModelForm, Form), {})().fields.keys()), ['name']) - self.assertEqual(list(type(str('NewForm'), (ModelForm, Mixin, Form), {})().fields.keys()), ['name']) - self.assertEqual(list(type(str('NewForm'), (ModelForm, Form, Mixin), {})().fields.keys()), ['name', 'age']) - self.assertEqual(list(type(str('NewForm'), (ModelForm, Form), {'age': None})().fields.keys()), ['name']) + self.assertEqual(list(type('NewForm', (Mixin, Form), {})().fields.keys()), []) + self.assertEqual(list(type('NewForm', (Form2, Mixin, Form), {})().fields.keys()), ['foo']) + self.assertEqual(list(type('NewForm', (Mixin, ModelForm, Form), {})().fields.keys()), ['name']) + self.assertEqual(list(type('NewForm', (ModelForm, Mixin, Form), {})().fields.keys()), ['name']) + self.assertEqual(list(type('NewForm', (ModelForm, Form, Mixin), {})().fields.keys()), ['name', 'age']) + self.assertEqual(list(type('NewForm', (ModelForm, Form), {'age': None})().fields.keys()), ['name']) def test_field_removal_name_clashes(self): """ diff --git a/tests/model_inheritance/test_abstract_inheritance.py b/tests/model_inheritance/test_abstract_inheritance.py index d74cae7a3b..4bd0654e46 100644 --- a/tests/model_inheritance/test_abstract_inheritance.py +++ b/tests/model_inheritance/test_abstract_inheritance.py @@ -322,11 +322,11 @@ class AbstractInheritanceTests(TestCase): return list((f.name, f.__class__) for f in model._meta.get_fields()) model_dict = {'__module__': 'model_inheritance'} - model1 = type(str('Model1'), (AbstractModel, Mixin), model_dict.copy()) - model2 = type(str('Model2'), (Mixin2, AbstractModel), model_dict.copy()) - model3 = type(str('Model3'), (DescendantMixin, AbstractModel), model_dict.copy()) - model4 = type(str('Model4'), (Mixin2, Mixin, AbstractModel), model_dict.copy()) - model5 = type(str('Model5'), (Mixin2, ConcreteModel2, Mixin, AbstractModel), model_dict.copy()) + model1 = type('Model1', (AbstractModel, Mixin), model_dict.copy()) + model2 = type('Model2', (Mixin2, AbstractModel), model_dict.copy()) + model3 = type('Model3', (DescendantMixin, AbstractModel), model_dict.copy()) + model4 = type('Model4', (Mixin2, Mixin, AbstractModel), model_dict.copy()) + model5 = type('Model5', (Mixin2, ConcreteModel2, Mixin, AbstractModel), model_dict.copy()) self.assertEqual( fields(model1), diff --git a/tests/queryset_pickle/tests.py b/tests/queryset_pickle/tests.py index ac5174051f..61ffba6c0b 100644 --- a/tests/queryset_pickle/tests.py +++ b/tests/queryset_pickle/tests.py @@ -82,8 +82,7 @@ class PickleabilityTestCase(TestCase): def test_model_pickle_dynamic(self): class Meta: proxy = True - dynclass = type(str("DynamicEventSubclass"), (Event, ), - {'Meta': Meta, '__module__': Event.__module__}) + dynclass = type("DynamicEventSubclass", (Event, ), {'Meta': Meta, '__module__': Event.__module__}) original = dynclass(pk=1) dumped = pickle.dumps(original) reloaded = pickle.loads(dumped) diff --git a/tests/servers/tests.py b/tests/servers/tests.py index bf87306cce..82c9bea493 100644 --- a/tests/servers/tests.py +++ b/tests/servers/tests.py @@ -111,7 +111,7 @@ class LiveServerPort(LiveServerBase): Each LiveServerTestCase binds to a unique port or fails to start a server thread when run concurrently (#26011). """ - TestCase = type(str("TestCase"), (LiveServerBase,), {}) + TestCase = type("TestCase", (LiveServerBase,), {}) try: TestCase.setUpClass() except socket.error as e: diff --git a/tests/validation/test_unique.py b/tests/validation/test_unique.py index 642154aaa7..11d06eeb4d 100644 --- a/tests/validation/test_unique.py +++ b/tests/validation/test_unique.py @@ -53,7 +53,7 @@ class GetUniqueCheckTests(unittest.TestCase): bar = models.IntegerField() baz = models.IntegerField() - Meta = type(str('Meta'), (), { + Meta = type('Meta', (), { 'unique_together': unique_together, 'apps': Apps() }) |
