launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #07450
[Merge] lp:~jtv/maas/reusable-map_enum into lp:maas
Jeroen T. Vermeulen has proposed merging lp:~jtv/maas/reusable-map_enum into lp:maas.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~jtv/maas/reusable-map_enum/+merge/104117
The long-awaited time has come when map_enum grew useful outside of tests. The details are in another branch, but first I have to lift it out of the testing directory.
You'll note that I swept map_enum into __init__.py, but kept its tests in a separate test module. There is no test_module.py yet to sweep it into, and as soon as we find ourselves adding another enum helper, I want to place this back into a module of its own anyway.
If this offends anyone, I could either re-create an enum.py in maasserver, or a test_module.py in maasserver/tests.
Jeroen
--
https://code.launchpad.net/~jtv/maas/reusable-map_enum/+merge/104117
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jtv/maas/reusable-map_enum into lp:maas.
=== modified file 'src/maasserver/__init__.py'
--- src/maasserver/__init__.py 2012-04-23 05:48:50 +0000
+++ src/maasserver/__init__.py 2012-04-30 14:09:32 +0000
@@ -12,6 +12,7 @@
__metaclass__ = type
__all__ = [
'DefaultMeta',
+ 'map_enum',
]
@@ -23,3 +24,17 @@
the model and will fail to generate schema migrations for it.
"""
app_label = 'maasserver'
+
+
+def map_enum(enum_class):
+ """Map out an enumeration class as a "NAME: value" dict."""
+ # Filter out anything that starts with '_', which covers private and
+ # special methods. We can make this smarter later if we start using
+ # a smarter enumeration base class etc. Or if we switch to a proper
+ # enum mechanism, this function will act as a marker for pieces of
+ # code that should be updated.
+ return {
+ key: value
+ for key, value in vars(enum_class).items()
+ if not key.startswith('_')
+ }
=== removed file 'src/maasserver/testing/enum.py'
--- src/maasserver/testing/enum.py 2012-04-16 10:00:51 +0000
+++ src/maasserver/testing/enum.py 1970-01-01 00:00:00 +0000
@@ -1,29 +0,0 @@
-# Copyright 2012 Canonical Ltd. This software is licensed under the
-# GNU Affero General Public License version 3 (see the file LICENSE).
-
-"""Enumeration helpers."""
-
-from __future__ import (
- absolute_import,
- print_function,
- unicode_literals,
- )
-
-__metaclass__ = type
-__all__ = [
- 'map_enum',
- ]
-
-
-def map_enum(enum_class):
- """Map out an enumeration class as a "NAME: value" dict."""
- # Filter out anything that starts with '_', which covers private and
- # special methods. We can make this smarter later if we start using
- # a smarter enumeration base class etc. Or if we switch to a proper
- # enum mechanism, this function will act as a marker for pieces of
- # code that should be updated.
- return {
- key: value
- for key, value in vars(enum_class).items()
- if not key.startswith('_')
- }
=== modified file 'src/maasserver/testing/factory.py'
--- src/maasserver/testing/factory.py 2012-04-30 02:30:50 +0000
+++ src/maasserver/testing/factory.py 2012-04-30 14:09:32 +0000
@@ -33,7 +33,7 @@
get_data,
reload_object,
)
-from maasserver.testing.enum import map_enum
+from maasserver import map_enum
import maastesting.factory
from metadataserver.models import NodeCommissionResult
=== modified file 'src/maasserver/tests/test_api.py'
--- src/maasserver/tests/test_api.py 2012-04-30 02:30:50 +0000
+++ src/maasserver/tests/test_api.py 2012-04-30 14:09:32 +0000
@@ -53,7 +53,7 @@
reload_object,
reload_objects,
)
-from maasserver.testing.enum import map_enum
+from maasserver import map_enum
from maasserver.testing.factory import factory
from maasserver.testing.oauthclient import OAuthAuthenticatedClient
from maasserver.testing.testcase import (
=== modified file 'src/maasserver/tests/test_components.py'
--- src/maasserver/tests/test_components.py 2012-04-16 10:00:51 +0000
+++ src/maasserver/tests/test_components.py 2012-04-30 14:09:32 +0000
@@ -22,7 +22,7 @@
get_persistent_errors,
register_persistent_error,
)
-from maasserver.testing.enum import map_enum
+from maasserver import map_enum
from maasserver.testing.factory import factory
from maasserver.testing.testcase import TestCase
=== renamed file 'src/maasserver/testing/tests/test_enum.py' => 'src/maasserver/tests/test_enum.py'
--- src/maasserver/testing/tests/test_enum.py 2012-04-16 10:00:51 +0000
+++ src/maasserver/tests/test_enum.py 2012-04-30 14:09:32 +0000
@@ -12,7 +12,7 @@
__metaclass__ = type
__all__ = []
-from maasserver.testing.enum import map_enum
+from maasserver import map_enum
from maastesting.testcase import TestCase
=== modified file 'src/maasserver/tests/test_models.py'
--- src/maasserver/tests/test_models.py 2012-04-27 13:55:54 +0000
+++ src/maasserver/tests/test_models.py 2012-04-30 14:09:32 +0000
@@ -64,7 +64,7 @@
)
from maasserver.provisioning import get_provisioning_api_proxy
from maasserver.testing import get_data
-from maasserver.testing.enum import map_enum
+from maasserver import map_enum
from maasserver.testing.factory import factory
from maasserver.testing.testcase import (
TestCase,
=== modified file 'src/maasserver/tests/test_provisioning.py'
--- src/maasserver/tests/test_provisioning.py 2012-04-20 15:16:41 +0000
+++ src/maasserver/tests/test_provisioning.py 2012-04-30 14:09:32 +0000
@@ -56,7 +56,7 @@
select_profile_for_node,
SHORT_PRESENTATIONS,
)
-from maasserver.testing.enum import map_enum
+from maasserver import map_enum
from maasserver.testing.factory import factory
from maasserver.testing.testcase import TestCase
from metadataserver.models import NodeKey
=== modified file 'src/maasserver/tests/test_views.py'
--- src/maasserver/tests/test_views.py 2012-04-30 08:10:51 +0000
+++ src/maasserver/tests/test_views.py 2012-04-30 14:09:32 +0000
@@ -26,7 +26,7 @@
from maasserver.components import register_persistent_error
from maasserver.exceptions import ExternalComponentException
from maasserver.testing import extract_redirect
-from maasserver.testing.enum import map_enum
+from maasserver import map_enum
from maasserver.testing.factory import factory
from maasserver.testing.testcase import (
LoggedInTestCase,
=== modified file 'src/maasserver/tests/test_views_nodes.py'
--- src/maasserver/tests/test_views_nodes.py 2012-04-30 08:10:51 +0000
+++ src/maasserver/tests/test_views_nodes.py 2012-04-30 14:09:32 +0000
@@ -36,7 +36,7 @@
reload_object,
reload_objects,
)
-from maasserver.testing.enum import map_enum
+from maasserver import map_enum
from maasserver.testing.factory import factory
from maasserver.testing.testcase import (
AdminLoggedInTestCase,
=== modified file 'src/provisioningserver/tests/test_api.py'
--- src/provisioningserver/tests/test_api.py 2012-04-20 11:00:49 +0000
+++ src/provisioningserver/tests/test_api.py 2012-04-30 14:09:32 +0000
@@ -22,7 +22,7 @@
from base64 import b64decode
from contextlib import contextmanager
-from maasserver.testing.enum import map_enum
+from maasserver import map_enum
from maastesting.factory import factory
from provisioningserver.api import (
cobbler_to_papi_distro,