1 | import json
|
---|
2 | from pickle import NONE
|
---|
3 | from typing import List
|
---|
4 | import unittest
|
---|
5 |
|
---|
6 | from pyson.ObjectMapper import ObjectMapper
|
---|
7 | from unitpy.GeneralTests import GeneralTests
|
---|
8 |
|
---|
9 | from geniusweb.issuevalue.DiscreteValue import DiscreteValue
|
---|
10 | from geniusweb.issuevalue.Value import Value
|
---|
11 |
|
---|
12 |
|
---|
13 | class DiscreteValueTest(unittest.TestCase, GeneralTests[DiscreteValue]):
|
---|
14 | value = DiscreteValue("a")
|
---|
15 | value1 = DiscreteValue("a")
|
---|
16 | valueb = DiscreteValue("b")
|
---|
17 |
|
---|
18 | serialized = "\"a\"";
|
---|
19 | jackson = ObjectMapper();
|
---|
20 |
|
---|
21 | def testSerialize(self):
|
---|
22 | print(str(self.jackson.toJson(self.value)))
|
---|
23 | self.assertEqual(json.loads(self.serialized), self.jackson.toJson(self.value))
|
---|
24 |
|
---|
25 | def testEmpty(self):
|
---|
26 | self.assertRaises(ValueError, lambda:DiscreteValue(""))
|
---|
27 |
|
---|
28 | def testDeserialize(self) :
|
---|
29 | self.assertEqual(self.value, self.jackson.parse(json.loads(self.serialized), DiscreteValue))
|
---|
30 |
|
---|
31 | def testDeserializeFromValue(self):
|
---|
32 | self.assertEqual(self.value, self.jackson.parse(json.loads(self.serialized), Value))
|
---|
33 |
|
---|
34 | def getGeneralTestData(self)->List[List[DiscreteValue]] :
|
---|
35 | return [ [self.value, self.value1], [self.valueb]]
|
---|
36 |
|
---|
37 | def getGeneralTestStrings(self)->List[str]:
|
---|
38 | return [self.serialized, "\"b\""]
|
---|
39 | |
---|