def test_list_creation_with_list_items(self) -> None: a = ["one", "two", "three"] b = ["cyan", "magenta", "yellow"] c = ["foo", "bar", "baz"] d = ["I", "II", "III"] StrList2D([a, b, c, d]) with self.assertRaises(TypeError): StrList2D([a, [None]]) # type: ignore
def test_list_creation_with_list_items(self) -> None: a = ['one', 'two', 'three'] b = ['cyan', 'magenta', 'yellow'] c = ['foo', 'bar', 'baz'] d = ['I', 'II', 'III'] StrList2D([a, b, c, d]) with self.assertRaises(TypeError): StrList2D([a, [None]]) # type: ignore
def test_list_creation_with_list_items(self) -> None: a = ["one", "two", "three"] b = ["cyan", "magenta", "yellow"] c = ["foo", "bar", "baz"] d = ["I", "II", "III"] StrList2D([a, b, c, d]) with self.assertRaises(TypeError): # pyre-fixme[6]: Expected # `Optional[typing.Sequence[typing.Sequence[str]]]` for 1st param but got # `List[typing.Union[typing.List[None], typing.List[str]]]`. StrList2D([a, [None]])
def test_cached_list(self) -> None: uncached = StrList2D([["one", "two"], ["cyan", "magenta"]]) # default no cache, so every access creates a new instance self.assertIsNot(uncached[0], uncached[0]) # with cache they should be same self.assertIs(to_tuple(uncached)[0], to_tuple(uncached)[0]) # nested list are still not cached by default self.assertIsNot(to_tuple(uncached)[0][0], to_tuple(uncached)[0][0]) self.assertIs( to_tuple(to_tuple(uncached)[0])[0], to_tuple(to_tuple(uncached)[0])[0])
def test_is_container(self) -> None: self.assertIsInstance(int_list, Container) self.assertIsInstance(I32List([1, 2, 3]), Container) self.assertIsInstance(StrList2D([["a", "b"], ["c", "d"]]), Container)