Beispiel #1
0
 def test_tuples(self):
     typeassert((1, 2, 3), '(int,int,int)')
     typeassert((1, 2, 3), '(int..)')
     typeassert((1., 2.), '(float..)')  # handled as '(1. ..)'
     typeassert((1, "deux"), '()')
     with self.assertRaises(TypeassertException):
         typeassert((1, 2, 3), '(float)')
Beispiel #2
0
 def test_tuples(self):
   typeassert((1,2,3), '(int,int,int)')
   typeassert((1,2,3), '(int..)')
   typeassert((1.,2.), '(float..)') # handled as '(1. ..)'
   typeassert((1, "deux"), '()')
   with self.assertRaises(TypeassertException):
     typeassert((1,2,3), '(float)')
Beispiel #3
0
 def test_set(self):
   typeassert({11, 2},  '{int}')
   typeassert({11, 2, 123},  '{}')
   with self.assertRaises(TypeassertException):
     typeassert({11, 's'},  '{int}')
   with self.assertRaises(TypeassertException):
     typeassert([11, 's'],  '{int}')
Beispiel #4
0
 def test_floats(self):
     typeassert(1.2, 'float')
     typeassert(1.2, 'float')
     with self.assertRaises(TypeassertException):
         typeassert(12.0, 'str')
     with self.assertRaises(TypeassertException):
         typeassert('bla', 'float')
Beispiel #5
0
 def test_floats(self):
   typeassert(1.2, 'float')
   typeassert(1.2, 'float')
   with self.assertRaises(TypeassertException):
     typeassert(12.0, 'str')
   with self.assertRaises(TypeassertException):
     typeassert('bla', 'float')
Beispiel #6
0
 def test_int(self):
   typeassert(12, 'int')
   typeassert(-12, 'int')
   with self.assertRaises(TypeassertException):
     typeassert(12, 'str')
   with self.assertRaises(TypeassertException):
     typeassert('bla', 'int')
Beispiel #7
0
 def test_int(self):
     typeassert(12, 'int')
     typeassert(-12, 'int')
     with self.assertRaises(TypeassertException):
         typeassert(12, 'str')
     with self.assertRaises(TypeassertException):
         typeassert('bla', 'int')
Beispiel #8
0
 def test_set(self):
     typeassert({11, 2}, '{int}')
     typeassert({11, 2, 123}, '{}')
     with self.assertRaises(TypeassertException):
         typeassert({11, 's'}, '{int}')
     with self.assertRaises(TypeassertException):
         typeassert([11, 's'], '{int}')
Beispiel #9
0
 def test_dict(self):
     typeassert({11: 2}, '{int:int}')
     typeassert({11: 2, 12: 3}, '{}')
     typeassert({11: 2, 12: 3}, '{int:int}')
     typeassert({
         11: 2,
         12: 3
     }, '{int:int, int:int}')  #should fail, though...
Beispiel #10
0
    def test_bypass(self):

        disable_typeassert()

        typeassert(12, 'str')  # typeassert not activated
        typeassert(12, 'int', True)  # bypass activation
        with self.assertRaises(TypeassertException):
            typeassert(12, 'str', True)

        activate_typeassert()
Beispiel #11
0
  def test_bypass(self):

    disable_typeassert()

    typeassert(12, 'str') # typeassert not activated
    typeassert(12, 'int', True) # bypass activation
    with self.assertRaises(TypeassertException):
      typeassert(12, 'str', True)

    activate_typeassert()
Beispiel #12
0
 def test_missing_item(self):
   with self.assertRaises(TypeassertException):
     typeassert((12), '(*, int)')
Beispiel #13
0
 def test_array(self):
     typeassert([1, 2, 3], '[int,int,int]')
     typeassert([1, 2, 3], '[int..]')
     typeassert([1, "deux"], '[]')
     with self.assertRaises(TypeassertException):
         typeassert([1, 2, 3], 'int')
     with self.assertRaises(
             TypeassertException):  # spec is not of same type
         typeassert(1, '[int]')
     with self.assertRaises(TypeassertException):  # spec is longer
         typeassert([1, 2], '[int,int,int]')
Beispiel #14
0
 def test_array(self):
   typeassert([1,2,3], '[int,int,int]')
   typeassert([1,2,3], '[int..]')
   typeassert([1, "deux"], '[]')
   with self.assertRaises(TypeassertException):
     typeassert([1,2,3], 'int')
   with self.assertRaises(TypeassertException): # spec is not of same type
     typeassert(1, '[int]')
   with self.assertRaises(TypeassertException): # spec is longer
     typeassert([1,2], '[int,int,int]')
Beispiel #15
0
 def test_dict(self):
   typeassert({11:2},         '{int:int}')
   typeassert({11:2, 12: 3},  '{}')
   typeassert({11:2, 12: 3},  '{int:int}')
   typeassert({11:2, 12: 3},  '{int:int, int:int}') #should fail, though...
Beispiel #16
0
 def test_multiple(self):
     typeassert((2, "asdf"), "(int,str)", (2, "asdf"), "(int,str)")
Beispiel #17
0
 def test_multiple(self):
   typeassert((2, "asdf"), "(int,str)", (2, "asdf"), "(int,str)")
Beispiel #18
0
 def test_dotdot(self):
     typeassert(['a'], '[str..]')
     with self.assertRaises(TypeassertException):
         typeassert(['a'], '[str...]')
     typeassert(['a', 'b', 'c'], '[str..]')
     with self.assertRaises(TypeassertException):
         typeassert([12, 'a', 'b', 'c'], '[int, str..]')
     with self.assertRaises(TypeassertException):
         typeassert([12, 13, 'b', 'c'], '[int, int, str..]')
     with self.assertRaises(TypeassertException):
         typeassert([12, 13, 'b', 'c'], '[int.., str..]')
Beispiel #19
0
 def test_wildcard(self):
     typeassert(12, '*')
Beispiel #20
0
 def test_wildcard(self):
   typeassert(12, '*')
Beispiel #21
0
 def test_dotdot(self):
   typeassert(['a'], '[str..]')
   with self.assertRaises(TypeassertException):
     typeassert(['a'], '[str...]')
   typeassert(['a', 'b', 'c'], '[str..]')
   with self.assertRaises(TypeassertException):
     typeassert([12, 'a', 'b', 'c'], '[int, str..]')
   with self.assertRaises(TypeassertException):
     typeassert([12, 13, 'b', 'c'], '[int, int, str..]')
   with self.assertRaises(TypeassertException):
     typeassert([12, 13, 'b', 'c'], '[int.., str..]')
Beispiel #22
0
 def test_named_variables(self):
   typeassert(12, 'my_name@int')
   typeassert([12], '[my_other_name@int]')
   typeassert((12,'s'), '(a@int, b@str)')
   typeassert(12, 'my-name@int')
   typeassert(12, 'my9@int')
   with self.assertRaises(TypeassertException):
     typeassert(12, 'my/name@int')
   with self.assertRaises(TypeassertException):
     typeassert(12, 'my name@int')
Beispiel #23
0
 def test_missing_item(self):
     with self.assertRaises(TypeassertException):
         typeassert((12), '(*, int)')
Beispiel #24
0
 def test_mixes(self):
     #typeassert({11: (2,3), 12: (4,"5")}, '{ int: (int,*)}')
     typeassert([(2, "asdf"), (-12, "asfwe"), (1, "")], "[(int,str)..]")
     with self.assertRaises(TypeassertException):
         typeassert({11: (2, 3), 12: (4, "5")}, '{ int: (int,int)}')
Beispiel #25
0
 def test_named_variables(self):
     typeassert(12, 'my_name@int')
     typeassert([12], '[my_other_name@int]')
     typeassert((12, 's'), '(a@int, b@str)')
     typeassert(12, 'my-name@int')
     typeassert(12, 'my9@int')
     with self.assertRaises(TypeassertException):
         typeassert(12, 'my/name@int')
     with self.assertRaises(TypeassertException):
         typeassert(12, 'my name@int')
Beispiel #26
0
 def test_mixes(self):
   #typeassert({11: (2,3), 12: (4,"5")}, '{ int: (int,*)}')
   typeassert([(2, "asdf"),(-12, "asfwe"),(1,"")], "[(int,str)..]")
   with self.assertRaises(TypeassertException):
     typeassert({11: (2,3), 12: (4,"5")}, '{ int: (int,int)}')