[pypy-svn] r49338 - in pypy/branch/clr-module-improvements/pypy/module/clr: . test

regmee at codespeak.net regmee at codespeak.net
Tue Dec 4 15:40:48 CET 2007


Author: regmee
Date: Tue Dec  4 15:40:47 2007
New Revision: 49338

Modified:
   pypy/branch/clr-module-improvements/pypy/module/clr/app_clr.py
   pypy/branch/clr-module-improvements/pypy/module/clr/test/test_clr.py
Log:
checking in failing test case for GetEnumerator when assigned to __iter__

Modified: pypy/branch/clr-module-improvements/pypy/module/clr/app_clr.py
==============================================================================
--- pypy/branch/clr-module-improvements/pypy/module/clr/app_clr.py	(original)
+++ pypy/branch/clr-module-improvements/pypy/module/clr/app_clr.py	Tue Dec  4 15:40:47 2007
@@ -86,27 +86,31 @@
         else:
             type.__setattr__(cls, name, value)
 
+#class Dummy(object):
+#    def __init__(self, iterObj):
+#        self.iterObj = iterObj
+#        self.index = 0 
+#
+#    def next(self):
+#        temp = self.index
+#        if self.index == self.iterObj.Count:
+#            raise StopIteration
+#        self.index = self.index + 1
+#        return self.iterObj.__getitem__(temp)
+
+
 class CliClassWrapper(object):
     __slots__ = ('__cliobj__',)
 
     def __init__(self, *args):
         import clr
         self.__cliobj__ = clr._CliObject_internal(self.__cliclass__, args)
-#        self.index = self.__cliobj__.__len__(self)
-#        self.index = self.__cliobj__.call_method('Count',1)
         print self.__cliobj__
-#        self.index = self.Count
-
-    def __iter__(self):
-        self.index = self.Count
-        return self 
-
-    def next(self):
-        if self.index == 0:
-            raise StopIteration
-        self.index = self.index - 1
-        return self.this[self.index] 
+        print self.Count
 
+#    def __iter__(self):
+#        return Dummy(self)
+#        return Dummy(self.Count, self.__getitem__(self.Count - 1))
 
 def build_wrapper(namespace, classname, staticmethods, methods, properties, indexers):
     fullname = '%s.%s' % (namespace, classname)
@@ -122,7 +126,9 @@
         if method == "GetEnumerator":
             print "Enumerator found .. Hurray !!!!!"
             # now add the __iter__ method to the class 
-#            d['__iter__'] = sampleIter().__iter__
+            d['__iter__'] = d['GetEnumerator']
+#            d['next'] = d['MoveNext']
+
 
     assert len(indexers) <= 1
     if indexers:
@@ -153,3 +159,8 @@
         setattr(cls, name, prop)
 
     return cls
+
+
+
+
+

Modified: pypy/branch/clr-module-improvements/pypy/module/clr/test/test_clr.py
==============================================================================
--- pypy/branch/clr-module-improvements/pypy/module/clr/test/test_clr.py	(original)
+++ pypy/branch/clr-module-improvements/pypy/module/clr/test/test_clr.py	Tue Dec  4 15:40:47 2007
@@ -148,3 +148,17 @@
         assert Environment.CurrentDirectory == os.getcwd()
         Environment.CurrentDirectory == '/'
         assert Environment.CurrentDirectory == os.getcwd()
+
+    def test_GetEnumerator(self):
+        import clr
+        ArrayList = clr.load_cli_class('System.Collections', 'ArrayList')
+        x = ArrayList()
+        x.Add(1)
+        x.Add(6)
+        x.Add(31)
+        x.Add(2)
+        for i in x:
+           print i 
+
+
+


More information about the pypy-svn mailing list