Пример #1
0
def getScreenRGB2(env):
    return List([
        List([
            int('#{:02x}{:02x}{:02x}'.format(j[0], j[1], j[2])[1:], 16)
            for j in i
        ]) for i in env.render(mode='rgb_array')
    ])
Пример #2
0
 def test_hash_list(self):
     input = Map({List([1, 2, 3]): [4, 5, 6]})
     self.assertEquals(
         input[List([1, 2, 3])],
         List([4, 5, 6])
     )
     self.assertEquals(
         (input, b""),
         decode(encode(input))
     )
Пример #3
0
def getScreenRGB3(env):
    rgb_array = env.render(mode='rgb_array')
    return List([
        List([List([j[0] for j in i]) for i in rgb_array]),
        List([List([j[1] for j in i]) for i in rgb_array]),
        List([List([j[2] for j in i]) for i in rgb_array])
    ])
Пример #4
0
    def test_encode_map(self):
        self.assertEqual(
            b"\x83t\x00\x00\x00\x01t\x00\x00\x00\x00t\x00\x00\x00\x00",
            encode(Map({Map(): Map()})))

        self.assertEqual(
            b'\x83t\x00\x00\x00\x01k\x00\x06hello1k\x00\x06world1',
            encode(Map({b"hello1": b"world1"})))

        self.assertEqual(
            b"\x83t\x00\x00\x00\x01k\x00\x06hello1k\x00\x03\x01\x02\x03",
            encode(Map({b"hello1": List([1, 2, 3])})))
Пример #5
0
 def test_encode_list(self):
     self.assertEqual("\x83l\0\0\0\1jj", encode([[]]))
     self.assertEqual("\x83l\0\0\0\5jjjjjj", encode([[], [], [], [], []]))
     self.assertEqual(
         "\x83l\0\0\0\5jjjjjj",
         encode(List([List([]),
                      List([]),
                      List([]),
                      List([]),
                      List([])])))
Пример #6
0
    def test_encode_map(self):
        self.assertEqual(
            "\x83t\x00\x00\x00\x01t\x00\x00\x00\x00t\x00\x00\x00\x00",
            encode(Map({Map(): Map()}))
        )

        self.assertEqual(
            "\x83t\x00\x00\x00\x01m\x00\x00\x00\x06"
            "hello1m\x00\x00\x00\x06world1",
            encode(Map(hello1="world1"))
        )

        self.assertEqual(
            "\x83t\x00\x00\x00\x01m\x00\x00\x00\x06"
            "hello1k\x00\x03\x01\x02\x03",
            encode(Map(hello1=List([1, 2, 3])))
        )
Пример #7
0
    def test_decode_map(self):
        self.assertEqual(
            (Map({"hello": "world"}), b""),
            decode(
                b"\x83t\x00\x00\x00\x01m\x00\x00\x00\x05hellom\x00\x00\x00\x05world"
            ))

        self.assertEqual(
            (Map({"hello": "world"}), b"rest"),
            decode(
                b"\x83t\x00\x00\x00\x01m\x00\x00\x00\x05hellom\x00\x00\x00\x05worldrest"
            ))

        self.assertEqual(
            (Map({"hello": List()}), b""),
            decode(b"\x83t\x00\x00\x00\x01m\x00\x00\x00\x05helloj"))

        self.assertRaises(IncompleteData, decode, b"\x83t\x00\x00\x00")
Пример #8
0
    def test_decode_map(self):
        self.assertEqual(
            (Map(hello="world"), ""),
            decode(
                "\x83t\x00\x00\x00\x01m\x00\x00\x00\x05"
                "hellom\x00\x00\x00\x05world")
        )

        self.assertEqual(
            (Map(hello="world"), "rest"),
            decode(
                "\x83t\x00\x00\x00\x01m\x00\x00\x00\x05"
                "hellom\x00\x00\x00\x05worldrest")
        )

        self.assertEqual(
            (Map(hello=List()), ""),
            decode("\x83t\x00\x00\x00\x01m\x00\x00\x00\x05helloj")
        )

        self.assertRaises(IncompleteData, decode, "\x83t\x00\x00\x00")
Пример #9
0
 def test_to_string(self):
     lst = List([116, 101, 115, 116])
     self.assertEqual(u"test", lst.to_string())
     self.assertTrue(isinstance(lst.to_string(), unicode))
     self.assertRaises(TypeError, List("ab").to_string)
Пример #10
0
 def test_list(self):
     lst = List([116, 101, 115, 116])
     self.assertTrue(isinstance(lst, list))
     self.assertEqual([116, 101, 115, 116], lst)
     self.assertEqual("List([116, 101, 115, 116])", repr(lst))
Пример #11
0
 def test_nested_list(self):
     input = List([[[[[[]]]]]])
     self.assertEquals(
         (input, b""),
         decode(encode(input))
     )
Пример #12
0
 def test_simple_list(self):
     input = List([1, 2, 3])
     self.assertEquals(
         (input, b""),
         decode(encode(input))
     )
Пример #13
0
 def test_empty_list(self):
     input = List()
     self.assertEquals(
         (input, b""),
         decode(encode(input))
     )