@@ -68,22 +68,23 @@ def _raise_namespace_clash(self, name):
6868 def clear (self ):
6969 self ._namespace = {}
7070
71+ def data (self ):
72+ '''Give access to the underlying namespace'''
73+ return self ._namespace
74+
7175
7276class Namespace (LocalNamespace , metaclass = abc .ABCMeta ):
7377 '''Namespace of a regression test.
7478
75- The final namespace may be built by inheriting namespaces from
76- the base classes, and extended with the information stored in the local
77- namespace of the target class. In this context, the target class is
78- simply the regression test class where the namespace is to be built.
79-
80- To allow for this inheritance and extension of the namespace, this
81- class must define the names under which the local and final namespaces
82- are inserted in the target classes.
79+ The final namespace may be built by inheriting namespaces from the base
80+ classes, and extending this one with the information stored in the local
81+ namespace of the target class. In this context, the target class is simply
82+ the regression test class where the namespace is to be built.
8383
84- If a target class is provided, the constructor will attach the Namespace
85- instance into the target class with the class attribute name as defined
86- in ``namespace_name``.
84+ If a target class is provided, the constructor will build a Namespace
85+ instance by inheriting the namespaces found in the base classes, and
86+ extending this with the information from the local namespace of the
87+ target class.
8788
8889 Eventually, the items from a Namespace are injected as attributes of
8990 the target class instance by the :func:`inject` method, which must be
@@ -95,32 +96,15 @@ class may use more that one Namespace, which raises the need for name
9596 target class. Then, after the Namespace is built, if ``illegal_names`` is
9697 provided, a sanity check is performed, ensuring that no name clashing
9798 will occur during the target class instantiation process.
98- '''
9999
100- @property
101- @abc .abstractmethod
102- def local_namespace_name (self ):
103- '''Name of the local namespace in the target class.
104-
105- Name under which the local namespace is stored in the
106- :class:`reframe.core.pipeline.RegressionTest` class.
107- '''
108-
109- @property
110- @abc .abstractmethod
111- def namespace_name (self ):
112- '''Name of the namespace in the target class.
113-
114- Name under which the namespace is stored in the
115- :class:`reframe.core.pipeline.RegressionTest` class.
116- '''
100+ '''
117101
118- def __init__ (self , target_cls = None , illegal_names = None ):
102+ def __init__ (self , target_cls = None , illegal_names = None ,
103+ * , ns_name , ns_local_name ):
119104 super ().__init__ ()
105+ self ._ns_name = ns_name
106+ self ._ns_local_name = ns_local_name
120107 if target_cls :
121- # Assert the Namespace can be built for the target_cls
122- self .assert_target_cls (target_cls )
123-
124108 # Inherit Namespaces from the base clases
125109 self .inherit (target_cls )
126110
@@ -130,23 +114,21 @@ def __init__(self, target_cls=None, illegal_names=None):
130114 # Sanity checkings on the resulting Namespace
131115 self .sanity (target_cls , illegal_names )
132116
133- # Attach the Namespace to the target class
134- setattr (target_cls , self .namespace_name , self )
135-
136- def assert_target_cls (self , cls ):
137- '''Assert the target class has a valid local namespace.'''
117+ @property
118+ def namespace_name (self ):
119+ return self ._ns_name
138120
139- assert hasattr ( cls , self . local_namespace_name )
140- assert isinstance ( getattr ( cls , self . local_namespace_name ),
141- LocalNamespace )
121+ @ property
122+ def local_namespace_name ( self ):
123+ return self . _ns_local_name
142124
143125 def inherit (self , cls ):
144126 '''Inherit the Namespaces from the bases.'''
145127
146- for base in filter ( lambda x : hasattr ( x , self . namespace_name ),
147- cls . __bases__ ):
148- assert isinstance (getattr ( base , self . namespace_name ), type (self ))
149- self .join (getattr ( base , self . namespace_name ) , cls )
128+ for base in cls . __bases__ :
129+ other = getattr ( base , self . namespace_name , None )
130+ if isinstance (other , type (self )):
131+ self .join (other , cls )
150132
151133 @abc .abstractmethod
152134 def join (self , other , cls ):
@@ -156,7 +138,7 @@ def join(self, other, cls):
156138 def extend (self , cls ):
157139 '''Extend the namespace with the local namespace.'''
158140
159- def sanity (self , cls , illegal_names = None ):
141+ def sanity (self , cls , illegal_names ):
160142 '''Sanity checks post-creation of the namespace.
161143
162144 By default, we make illegal to have any item in the namespace
0 commit comments