Revision fd0351ae test/ganeti.serializer_unittest.py

b/test/ganeti.serializer_unittest.py
23 23

  
24 24

  
25 25
import unittest
26
import warnings
26 27

  
27 28
from ganeti import serializer
28 29
from ganeti import errors
30
from ganeti import compat
29 31

  
30 32
import testutils
31 33

  
......
107 109
                      serializer.DumpJson(tdata), "mykey")
108 110

  
109 111

  
112
class TestInvalidDictionaryKey(unittest.TestCase):
113
  def _Test(self, data):
114
    if serializer._OLD_SIMPLEJSON:
115
      # Using old "simplejson", can't really test
116
      warnings.warn("This test requires Python 2.6 or above to function"
117
                    " correctly")
118
      self.assertTrue(serializer.DumpJson(data))
119
    else:
120
      self.assertRaises(ValueError, serializer.DumpJson, data)
121

  
122
  def test(self):
123
    for value in [123, 1.1, -1, -9492.1123, -3234e-4]:
124
      self._Test({value: ""})
125

  
126
  def testAllowed(self):
127
    for value in ["", "Hello World", None, True, False]:
128
      self.assertTrue(serializer.DumpJson({value: ""}))
129

  
130

  
110 131
if __name__ == '__main__':
111 132
  testutils.GanetiTestProgram()

Also available in: Unified diff