Exemple #1
0
 def test_None(self):
     with self.assertRaises(TypeError):
         StrIntMap({None: 5})
     with self.assertRaises(TypeError):
         StrIntMap({'foo': None})
     with self.assertRaises(TypeError):
         StrStrIntListMapMap({'bar': {'foo': [None, None]}})
     with self.assertRaises(TypeError):
         StrStrIntListMapMap({'bar': {'foo': None}})
Exemple #2
0
 def test_None(self) -> None:
     with self.assertRaises(TypeError):
         StrIntMap({None: 5})  # type: ignore
     with self.assertRaises(TypeError):
         StrIntMap({"foo": None})  # type: ignore
     with self.assertRaises(TypeError):
         StrStrIntListMapMap({"bar": {"foo": [None, None]}})  # type: ignore
     with self.assertRaises(TypeError):
         StrStrIntListMapMap({"bar": {"foo": None}})  # type: ignore
Exemple #3
0
 def test_mixed_construction(self):
     s = StrI32ListMap({'bar': [0, 1]})
     x = StrStrIntListMapMap({'foo': s})
     px = dict(x)
     px['baz'] = {'wat': [4]}
     px['foo'] = dict(px['foo'])
     px['foo']['bar'] = px['foo']['bar'] + [5, 7, 8]
     self.assertEquals(s['bar'], [0, 1])
     # Now turn this crazy mixed structure back to Cython
     cx = StrStrIntListMapMap(px)
     px['bar'] = {'lol': 'TypeError'}
     with self.assertRaises(TypeError):
         StrStrIntListMapMap(px)
     self.assertNotIn('bar', cx)
Exemple #4
0
 def test_mixed_construction(self) -> None:
     s = StrI32ListMap({"bar": [0, 1]})
     x = StrStrIntListMapMap({"foo": s})
     px: Dict[str, Dict[str, List[int]]] = {}
     px["foo"] = x["foo"]  # type: ignore
     px["baz"] = {"wat": [4]}
     px["foo"] = dict(px["foo"])
     px["foo"]["bar"] = px["foo"]["bar"] + [5, 7, 8]
     self.assertEquals(s["bar"], [0, 1])
     # Now turn this crazy mixed structure back to Cython
     cx = StrStrIntListMapMap(px)
     px["bar"] = {"lol": "TypeError"}  # type: ignore
     with self.assertRaises(TypeError):
         StrStrIntListMapMap(px)
     self.assertNotIn("bar", cx)
Exemple #5
0
 def test_map_key_value(self) -> None:
     x = StrStrIntListMapMap({"a": StrI32ListMap({"b": I32List([7, 8, 9])})})
     self.assertTrue(inspectable(x))
     self.assertTrue(inspectable(StrStrIntListMapMap))
     r = inspect(x)
     self.assertEqual(r.key, str)
     self.assertEqual(r.value, StrI32ListMap)
Exemple #6
0
 def test_mixed_construction(self) -> None:
     s = StrI32ListMap({"bar": [0, 1]})
     x = StrStrIntListMapMap({"foo": s})
     px: Dict[str, Dict[str, List[int]]] = {}
     # pyre-fixme[6]: Expected `Dict[str, List[int]]` for 2nd param but got
     #  `Mapping[str, typing.Sequence[int]]`.
     px["foo"] = x["foo"]
     px["baz"] = {"wat": [4]}
     px["foo"] = dict(px["foo"])
     px["foo"]["bar"] = px["foo"]["bar"] + [5, 7, 8]
     self.assertEquals(s["bar"], [0, 1])
     # Now turn this crazy mixed structure back to Cython
     cx = StrStrIntListMapMap(px)
     # pyre-fixme[6]: Expected `Dict[str, List[int]]` for 2nd param but got
     #  `Dict[str, str]`.
     px["bar"] = {"lol": "TypeError"}
     with self.assertRaises(TypeError):
         StrStrIntListMapMap(px)
     self.assertNotIn("bar", cx)
Exemple #7
0
 def test_None(self) -> None:
     with self.assertRaises(TypeError):
         # pyre-fixme[6]: Expected `Optional[typing.Mapping[str, int]]` for 1st
         #  param but got `Dict[None, int]`.
         StrIntMap({None: 5})
     with self.assertRaises(TypeError):
         # pyre-fixme[6]: Expected `Optional[typing.Mapping[str, int]]` for 1st
         #  param but got `Dict[str, None]`.
         StrIntMap({"foo": None})
     with self.assertRaises(TypeError):
         # pyre-fixme[6]: Expected `Optional[typing.Mapping[str,
         #  typing.Mapping[str, typing.Sequence[int]]]]` for 1st param but got
         #  `Dict[str, Dict[str, List[None]]]`.
         StrStrIntListMapMap({"bar": {"foo": [None, None]}})
     with self.assertRaises(TypeError):
         # pyre-fixme[6]: Expected `Optional[typing.Mapping[str,
         #  typing.Mapping[str, typing.Sequence[int]]]]` for 1st param but got
         #  `Dict[str, Dict[str, None]]`.
         StrStrIntListMapMap({"bar": {"foo": None}})
Exemple #8
0
 def test_hashability(self) -> None:
     hash(StrI32ListMap())
     x = StrStrIntListMapMap({"foo": StrI32ListMap()})
     hash(x["foo"])
Exemple #9
0
 def test_empty(self) -> None:
     StrIntMap()
     StrIntMap({})
     StrStrIntListMapMap({})
     StrStrIntListMapMap({"foo": {}})
     StrStrIntListMapMap({"foo": {"bar": []}})
Exemple #10
0
 def test_is_container(self) -> None:
     self.assertIsInstance(LocationMap, Container)
     self.assertIsInstance(StrI32ListMap(), Container)
     self.assertIsInstance(StrIntMap(), Container)
     self.assertIsInstance(StrStrIntListMapMap(), Container)
     self.assertIsInstance(StrStrMap(), Container)
Exemple #11
0
 def test_hashability(self) -> None:
     hash(StrI32ListMap())
     x = StrStrIntListMapMap({'foo': StrI32ListMap()})
     hash(x['foo'])
Exemple #12
0
 def test_empty(self) -> None:
     StrIntMap()
     StrIntMap({})
     StrStrIntListMapMap({})
     StrStrIntListMapMap({'foo': {}})
     StrStrIntListMapMap({'foo': {'bar': []}})