On Tue, 2007-03-13 at 19:51 +1100, Edward d'Auvergne wrote:
> Gary,
>
> I've written some unit tests which are located in the file
> 'test_suite/unit_tests/data/__init__.py'. Would you know what
> modifications I need to apply to make these tests run? These tests
> are for the methods of the Data singleton class (the relax data
> storage object) which is located in 'data/__init__.py'. I haven't
> used the statement 'from x import Data' for this class so it is the
> legal and ubiquitous usage of an __init__.py file. Would
> 'unit_test_runner.py' handle this code?
>
> Thanks,
>
> Edward
>
>
> P.S. These tests demonstrate the utility of subclassing the singleton
> and is one reason I was arguing for the use of the class import rather
> than reference import.
>
It is of course correct that the Singleton implimentation I proposed
does not allow for subclassing. This however might well be seen as a
design feature, given the well known conceptual problems with
subclassing Singleton. Essentially, subclassing violates the Singleton
Design Pattern:
class Singleton:
def __new__(self):
...
class Sub(Singleton): pass
>>> a = Singleton()
>>> b = Sub()
>>> isinstance(a,Singleton)
True
>>> isinstance(b,Singleton)
True
>>> a is b
False
>>> a == b
False
ie. we have 2 instances of Singleton that are not the same thing, and
not even equal! If this is the behaviour you want, then you need
something other than Singleton. On the other hand, if you really want
Singleton, then you can't also hope for subclassability.
Chris
> _______________________________________________
> relax (http://nmr-relax.com)
>
> This is the relax-devel mailing list
> [email protected]
>
> To unsubscribe from this list, get a password
> reminder, or change your subscription options,
> visit the list information page at
> https://mail.gna.org/listinfo/relax-devel
>
_______________________________________________
relax (http://nmr-relax.com)
This is the relax-devel mailing list
[email protected]
To unsubscribe from this list, get a password
reminder, or change your subscription options,
visit the list information page at
https://mail.gna.org/listinfo/relax-devel