예제 #1
0
 def test_cache(self):
     import clr
     ArrayList = clr.load_cli_class(self.mscorlib, 'System.Collections',
                                    'ArrayList')
     ArrayList2 = clr.load_cli_class(self.mscorlib, 'System.Collections',
                                     'ArrayList')
     assert ArrayList is ArrayList2
예제 #2
0
 def test_None_as_null(self):
     import clr
     ArrayList = clr.load_cli_class('System.Collections', 'ArrayList')
     Hashtable = clr.load_cli_class('System.Collections', 'Hashtable')
     x = ArrayList()
     x.Add(None)
     assert x[0] is None
     y = Hashtable()
     assert y["foo"] is None
예제 #3
0
 def test_None_as_null(self):
     import clr
     ArrayList = clr.load_cli_class(self.mscorlib, 'System.Collections',
                                    'ArrayList')
     Hashtable = clr.load_cli_class(self.mscorlib, 'System.Collections',
                                    'Hashtable')
     x = ArrayList()
     x.Add(None)
     assert x[0] is None
     y = Hashtable()
     assert y["foo"] is None
예제 #4
0
 def test_getitem(self):
     import clr
     ArrayList = clr.load_cli_class(self.mscorlib, 'System.Collections',
                                    'ArrayList')
     obj = ArrayList()
     obj.Add(42)
     assert obj[0] == 42
예제 #5
0
 def test_unboundmethod(self):
     import clr
     ArrayList = clr.load_cli_class(self.mscorlib, 'System.Collections',
                                    'ArrayList')
     obj = ArrayList()
     ArrayList.Add(obj, 42)
     assert obj.get_Item(0) == 42
예제 #6
0
 def test_GetEnumerator(self):
     import clr
     ArrayList = clr.load_cli_class(self.mscorlib, 'System.Collections',
                                    'ArrayList')
     x = ArrayList()
     enum = x.GetEnumerator()
     assert enum.MoveNext() is False
예제 #7
0
 def test_float_conversion(self):
     import clr
     ArrayList = clr.load_cli_class('System.Collections', 'ArrayList')
     obj = ArrayList()
     obj.Add(42.0)
     item = obj.get_Item(0)
     assert isinstance(item, float)
예제 #8
0
 def test_static_property(self):
     import clr
     import os
     Environment = clr.load_cli_class('System', 'Environment')
     assert Environment.CurrentDirectory == os.getcwd()
     Environment.CurrentDirectory == '/'
     assert Environment.CurrentDirectory == os.getcwd()
예제 #9
0
 def test_string_wrapping(self):
     import clr
     ArrayList = clr.load_cli_class('System.Collections', 'ArrayList')
     x = ArrayList()
     x.Add("bar")
     s = x[0]
     assert s == "bar"
예제 #10
0
 def test_generic_class_typeerror(self):
     import clr
     ListInt = clr.load_cli_class(self.mscorlib,
                                  "System.Collections.Generic",
                                  "List`1[System.Int32]")
     x = ListInt()
     raises(TypeError, x.Add, "test")
예제 #11
0
 def test_ArrayList(self):
     import clr
     ArrayList = clr.load_cli_class('System.Collections', 'ArrayList')
     obj = ArrayList()
     obj.Add(42)
     obj.Add(43)
     total = obj.get_Item(0) + obj.get_Item(1)
     assert total == 42+43
예제 #12
0
 def test_static_property(self):
     import clr
     import os
     Environment = clr.load_cli_class(self.mscorlib, 'System',
                                      'Environment')
     assert Environment.CurrentDirectory == os.getcwd()
     Environment.CurrentDirectory == '/'
     assert Environment.CurrentDirectory == os.getcwd()
예제 #13
0
 def test_property(self):
     import clr
     ArrayList = clr.load_cli_class('System.Collections', 'ArrayList')
     obj = ArrayList()
     obj.Add(42)
     assert obj.Count == 1
     obj.Capacity = 10
     assert obj.Capacity == 10
예제 #14
0
 def test_overload(self):
     import clr
     ArrayList = clr.load_cli_class('System.Collections', 'ArrayList')
     obj = ArrayList()
     for i in range(10):
         obj.Add(i)
     assert obj.IndexOf(7) == 7
     assert obj.IndexOf(7, 0, 5) == -1
예제 #15
0
 def test_float_conversion(self):
     import clr
     ArrayList = clr.load_cli_class(self.mscorlib, 'System.Collections',
                                    'ArrayList')
     obj = ArrayList()
     obj.Add(42.0)
     item = obj.get_Item(0)
     assert isinstance(item, float)
예제 #16
0
 def test_string_wrapping(self):
     import clr
     ArrayList = clr.load_cli_class(self.mscorlib, 'System.Collections',
                                    'ArrayList')
     x = ArrayList()
     x.Add("bar")
     s = x[0]
     assert s == "bar"
예제 #17
0
 def test_overload(self):
     import clr
     ArrayList = clr.load_cli_class(self.mscorlib, 'System.Collections',
                                    'ArrayList')
     obj = ArrayList()
     for i in range(10):
         obj.Add(i)
     assert obj.IndexOf(7) == 7
     assert obj.IndexOf(7, 0, 5) == -1
예제 #18
0
 def test_ArrayList(self):
     import clr
     ArrayList = clr.load_cli_class(self.mscorlib, 'System.Collections',
                                    'ArrayList')
     obj = ArrayList()
     obj.Add(42)
     obj.Add(43)
     total = obj.get_Item(0) + obj.get_Item(1)
     assert total == 42 + 43
예제 #19
0
 def test_staticmethod(self):
     import clr
     Math = clr.load_cli_class(self.mscorlib, 'System', 'Math')
     res = Math.Abs(-42)
     assert res == 42
     assert type(res) is int
     res = Math.Abs(-42.0)
     assert res == 42.0
     assert type(res) is float
예제 #20
0
 def test_staticmethod(self):
     import clr
     Math = clr.load_cli_class('System', 'Math')
     res = Math.Abs(-42)
     assert res == 42
     assert type(res) is int
     res = Math.Abs(-42.0)
     assert res == 42.0
     assert type(res) is float
예제 #21
0
 def test_property(self):
     import clr
     ArrayList = clr.load_cli_class(self.mscorlib, 'System.Collections',
                                    'ArrayList')
     obj = ArrayList()
     obj.Add(42)
     assert obj.Count == 1
     obj.Capacity = 10
     assert obj.Capacity == 10
예제 #22
0
 def test_pass_opaque_arguments(self):
     import clr
     ArrayList = clr.load_cli_class('System.Collections', 'ArrayList')
     class Foo:
         pass
     obj = Foo()
     x = ArrayList()
     x.Add(obj)
     obj2 = x[0]
     assert obj is obj2
예제 #23
0
파일: test_clr.py 프로젝트: Debug-Orz/Sypy
 def test_load_generic_class(self):
     import clr
     ListInt = clr.load_cli_class(self.mscorlib, "System.Collections.Generic", "List`1[System.Int32]")
     x = ListInt()
     x.Add(42)
     x.Add(4)
     x.Add(4)
     sum = 0
     for i in x:
        sum += i
     assert sum == 42+4+4
예제 #24
0
파일: test_clr.py 프로젝트: Debug-Orz/Sypy
 def test_iteration_stack(self):
     import clr
     Stack = clr.load_cli_class(self.mscorlib, 'System.Collections', 'Stack')
     obj = Stack()
     obj.Push(1)
     obj.Push(54)
     obj.Push(21)
     sum = 0
     for i in obj:
         sum += i
     assert sum == 1+54+21
예제 #25
0
파일: test_clr.py 프로젝트: Debug-Orz/Sypy
 def test_iteration_arrayList(self):
     import clr
     ArrayList = clr.load_cli_class(self.mscorlib, 'System.Collections', 'ArrayList')
     x = ArrayList()
     x.Add(1)
     x.Add(2)
     x.Add(3)
     x.Add(4)
     sum = 0
     for i in x:
        sum += i
     assert sum == 1+2+3+4
예제 #26
0
 def test_bool_conversion(self):
     import clr
     ArrayList = clr.load_cli_class('System.Collections', 'ArrayList')
     obj = ArrayList()
     obj.Add(True)
     obj.Add(False)
     t = obj.get_Item(0)
     f = obj.get_Item(1)
     assert t and isinstance(t, bool)
     assert not f and isinstance(f, bool)
     obj.Add(42)
     assert obj.Contains(42)
예제 #27
0
 def test_iteration_stack(self):
     import clr
     Stack = clr.load_cli_class(self.mscorlib, 'System.Collections',
                                'Stack')
     obj = Stack()
     obj.Push(1)
     obj.Push(54)
     obj.Push(21)
     sum = 0
     for i in obj:
         sum += i
     assert sum == 1 + 54 + 21
예제 #28
0
    def test_pass_opaque_arguments(self):
        import clr
        ArrayList = clr.load_cli_class(self.mscorlib, 'System.Collections',
                                       'ArrayList')

        class Foo:
            pass

        obj = Foo()
        x = ArrayList()
        x.Add(obj)
        obj2 = x[0]
        assert obj is obj2
예제 #29
0
 def test_iteration_arrayList(self):
     import clr
     ArrayList = clr.load_cli_class(self.mscorlib, 'System.Collections',
                                    'ArrayList')
     x = ArrayList()
     x.Add(1)
     x.Add(2)
     x.Add(3)
     x.Add(4)
     sum = 0
     for i in x:
         sum += i
     assert sum == 1 + 2 + 3 + 4
예제 #30
0
 def test_load_generic_class(self):
     import clr
     ListInt = clr.load_cli_class(self.mscorlib,
                                  "System.Collections.Generic",
                                  "List`1[System.Int32]")
     x = ListInt()
     x.Add(42)
     x.Add(4)
     x.Add(4)
     sum = 0
     for i in x:
         sum += i
     assert sum == 42 + 4 + 4
예제 #31
0
 def test_bool_conversion(self):
     import clr
     ArrayList = clr.load_cli_class(self.mscorlib, 'System.Collections',
                                    'ArrayList')
     obj = ArrayList()
     obj.Add(True)
     obj.Add(False)
     t = obj.get_Item(0)
     f = obj.get_Item(1)
     assert t and isinstance(t, bool)
     assert not f and isinstance(f, bool)
     obj.Add(42)
     assert obj.Contains(42)
예제 #32
0
파일: test_clr.py 프로젝트: Debug-Orz/Sypy
 def test_generic_dict(self):
     import clr
     genDictIntStr = clr.load_cli_class(self.mscorlib,
                                        "System.Collections.Generic",
                                        "Dictionary`2[System.Int32,System.String]")
     x = genDictIntStr()
     x[1] = "test"
     x[2] = "rest"
     assert x[1] == "test" 
     assert x[2] == "rest" 
     raises(TypeError, x.__setitem__, 3, 3)
     raises(TypeError, x.__setitem__, 4, 4.453)
     raises(TypeError, x.__setitem__, "test", 3)
예제 #33
0
 def test_generic_dict(self):
     import clr
     genDictIntStr = clr.load_cli_class(
         self.mscorlib, "System.Collections.Generic",
         "Dictionary`2[System.Int32,System.String]")
     x = genDictIntStr()
     x[1] = "test"
     x[2] = "rest"
     assert x[1] == "test"
     assert x[2] == "rest"
     raises(TypeError, x.__setitem__, 3, 3)
     raises(TypeError, x.__setitem__, 4, 4.453)
     raises(TypeError, x.__setitem__, "test", 3)
예제 #34
0
파일: app_clr.py 프로젝트: xx312022850/pypy
 def __getitem__(cls, type_or_tuple):
     import clr
     if isinstance(type_or_tuple, tuple):
         types = type_or_tuple
     else:
         types = (type_or_tuple,)
     namespace, generic_class = cls.__cliclass__.rsplit('.', 1)
     generic_params = [cls._cli_name(t) for t in types]        
     instance_class = '%s[%s]' % (generic_class, ','.join(generic_params))
     try:
         return clr.load_cli_class(cls.__assemblyname__, namespace, instance_class)
     except ImportError:
         raise TypeError, "Cannot load type %s.%s" % (namespace, instance_class)
예제 #35
0
    def test_import_hook_simple(self):
        mscorlib = 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
        import clr
        import System.Math

        assert System.Math.Abs(-5) == 5
        assert System.Math.Pow(2, 5) == 2**5

        Math = clr.load_cli_class(mscorlib, 'System', 'Math')
        assert Math is System.Math

        import System
        a = System.Collections.Stack()
        a.Push(3)
        a.Push(44)
        sum = 0
        for i in a:
           sum += i
        assert sum == 3+44

        import System.Collections.ArrayList
        ArrayList = clr.load_cli_class(mscorlib, 'System.Collections', 'ArrayList')
        assert ArrayList is System.Collections.ArrayList
예제 #36
0
    def load_module(self, fullname):
        '''
            The load_module() must fulfill the following *before* it runs any code:
            Note that the module object *must* be in sys.modules before the
            loader executes the module code.  

          A  If 'fullname' exists in sys.modules, the loader must use that
             else the loader must create a new module object and add it to sys.modules.

                module = sys.modules.setdefault(fullname, new.module(fullname))

          B  The __file__ attribute must be set.  String say "<frozen>"

          C  The __name__ attribute must be set.  If one uses
              imp.new_module() then the attribute is set automatically.

          D  If it\'s a package, the __path__ variable must be set.  This must
              be a list, but may be empty if __path__ has no further
              significance to the importer (more on this later).

          E  It should add a __loader__ attribute to the module, set to the loader object. 

        '''
        # If it is a call for a Class then return with the Class reference
        import clr
        namespaces, classes, generics = clr.get_assemblies_info()

        if fullname in classes:
            assemblyname = classes[fullname]
            fullname = generics.get(fullname, fullname)
            ns, classname = fullname.rsplit('.', 1)
            sys.modules[fullname] = clr.load_cli_class(assemblyname, ns, classname)
        else:  # if not a call for actual class (say for namespaces) assign an empty module 
            if fullname not in sys.modules:
                mod = CLRModule(fullname)
                mod.__file__ = "<%s>" % self.__class__.__name__
                mod.__loader__ = self
                mod.__name__ = fullname
                # add it to the modules dict
                sys.modules[fullname] = mod
            else:
                mod = sys.modules[fullname]

            # if it is a PACKAGE then we are to initialize the __path__ for the module
            # we won't deal with Packages here
        return sys.modules[fullname]
예제 #37
0
 def test_snippet_1(self):
     import clr
     ArrayList = clr.load_cli_class('System.Collections', 'ArrayList')
     obj = ArrayList()
     obj.Add(1)
예제 #38
0
 def test_wrong_overload(self):
     import clr
     Math = clr.load_cli_class('System', 'Math')
     raises(TypeError, Math.Abs, "foo")
예제 #39
0
 def test_unboundmethod_typeerror(self):
     import clr
     ArrayList = clr.load_cli_class(self.mscorlib, 'System.Collections',
                                    'ArrayList')
     raises(TypeError, ArrayList.Add)
     raises(TypeError, ArrayList.Add, 0)
예제 #40
0
 def test_unboundmethod_typeerror(self):
     import clr
     ArrayList = clr.load_cli_class('System.Collections', 'ArrayList')
     raises(TypeError, ArrayList.Add)
     raises(TypeError, ArrayList.Add, 0)
예제 #41
0
 def test_unboundmethod(self):
     import clr
     ArrayList = clr.load_cli_class('System.Collections', 'ArrayList')
     obj = ArrayList()
     ArrayList.Add(obj, 42)
     assert obj.get_Item(0) == 42
예제 #42
0
 def test_wrong_overload(self):
     import clr
     Math = clr.load_cli_class(self.mscorlib, 'System', 'Math')
     raises(TypeError, Math.Abs, "foo")
예제 #43
0
 def test_getitem(self):
     import clr
     ArrayList = clr.load_cli_class('System.Collections', 'ArrayList')
     obj = ArrayList()
     obj.Add(42)
     assert obj[0] == 42
예제 #44
0
 def test_constructor_args(self):
     import clr
     ArrayList = clr.load_cli_class(self.mscorlib, 'System.Collections',
                                    'ArrayList')
     obj = ArrayList(42)
     assert obj.Capacity == 42
예제 #45
0
 def test_ArrayList_error(self):
     import clr
     ArrayList = clr.load_cli_class(self.mscorlib, 'System.Collections',
                                    'ArrayList')
     obj = ArrayList()
     raises(StandardError, obj.get_Item, 0)
예제 #46
0
 def test_ArrayList_error(self):
     import clr
     ArrayList = clr.load_cli_class('System.Collections', 'ArrayList')
     obj = ArrayList()
     raises(StandardError, obj.get_Item, 0)
예제 #47
0
파일: test_clr.py 프로젝트: Debug-Orz/Sypy
 def test_GetEnumerator(self):
     import clr
     ArrayList = clr.load_cli_class(self.mscorlib, 'System.Collections', 'ArrayList')
     x = ArrayList()
     enum = x.GetEnumerator()
     assert enum.MoveNext() is False
예제 #48
0
 def test_cache(self):
     import clr
     ArrayList = clr.load_cli_class('System.Collections', 'ArrayList')
     ArrayList2 = clr.load_cli_class('System.Collections', 'ArrayList')
     assert ArrayList is ArrayList2
예제 #49
0
파일: test_clr.py 프로젝트: Debug-Orz/Sypy
 def test_generic_class_typeerror(self):
     import clr
     ListInt = clr.load_cli_class(self.mscorlib, "System.Collections.Generic", "List`1[System.Int32]")
     x = ListInt()
     raises(TypeError, x.Add, "test")
예제 #50
0
 def test_constructor_args(self):
     import clr
     ArrayList = clr.load_cli_class('System.Collections', 'ArrayList')
     obj = ArrayList(42)
     assert obj.Capacity == 42