本文整理匯總了Python中coilsnake.model.common.blocks.Block.to_list方法的典型用法代碼示例。如果您正苦於以下問題:Python Block.to_list方法的具體用法?Python Block.to_list怎麽用?Python Block.to_list使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類coilsnake.model.common.blocks.Block
的用法示例。
在下文中一共展示了Block.to_list方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_standard_text_to_block
# 需要導入模塊: from coilsnake.model.common.blocks import Block [as 別名]
# 或者: from coilsnake.model.common.blocks.Block import to_list [as 別名]
def test_standard_text_to_block():
b = Block()
b.from_list([0] * 10)
standard_text_to_block(block=b, offset=0, text="Test", max_length=10)
assert_list_equal(b.to_list(), [132, 149, 163, 164, 0, 0, 0, 0, 0, 0])
b.from_list([0x66] * 10)
standard_text_to_block(block=b, offset=0, text="Test", max_length=10)
assert_list_equal(b.to_list(), [132, 149, 163, 164, 0, 0x66, 0x66, 0x66, 0x66, 0x66])
示例2: test_to_block
# 需要導入模塊: from coilsnake.model.common.blocks import Block [as 別名]
# 或者: from coilsnake.model.common.blocks.Block import to_list [as 別名]
def test_to_block(self):
block = Block()
s = SwirlFrameRow(x1=3, x2=5, x3=55, x4=92)
block.from_list([33, 33, 33, 33, 33])
s.to_block(block, 1, False)
assert_equal([33, 3, 5, 55, 92], block.to_list())
s = SwirlFrameRow(x1=3, x2=5, x3=0xff, x4=0)
block.from_list([33, 33, 33, 33, 33])
s.to_block(block, 2, True)
assert_equal([33, 33, 3, 5, 33], block.to_list())
示例3: test_standard_text_to_block_with_brackets
# 需要導入模塊: from coilsnake.model.common.blocks import Block [as 別名]
# 或者: from coilsnake.model.common.blocks.Block import to_list [as 別名]
def test_standard_text_to_block_with_brackets():
b = Block()
b.from_list([0] * 10)
standard_text_to_block(block=b, offset=0, text="[01 02 03 04]", max_length=10)
assert_list_equal(b.to_list(), [0x01, 0x02, 0x03, 0x04, 0, 0, 0, 0, 0, 0])
b.from_list([0] * 10)
standard_text_to_block(block=b, offset=0, text="[]", max_length=10)
assert_list_equal(b.to_list(), [0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
b.from_list([0] * 10)
standard_text_to_block(block=b, offset=0, text="Te[ab cd ef]st", max_length=10)
assert_list_equal(b.to_list(), [132, 149, 0xab, 0xcd, 0xef, 163, 164, 0, 0, 0])
示例4: test_write_2bpp_graphic_to_block
# 需要導入模塊: from coilsnake.model.common.blocks import Block [as 別名]
# 或者: from coilsnake.model.common.blocks.Block import to_list [as 別名]
def test_write_2bpp_graphic_to_block():
source = [[2, 1, 2, 3, 2, 1, 2, 1],
[2, 3, 1, 0, 2, 3, 2, 2],
[3, 0, 3, 2, 2, 2, 0, 2],
[1, 3, 3, 0, 2, 0, 2, 3],
[1, 0, 1, 1, 0, 3, 3, 3],
[1, 3, 3, 3, 3, 2, 1, 2],
[2, 2, 3, 1, 2, 2, 1, 0],
[2, 0, 3, 3, 2, 3, 1, 0]]
target = Block()
target.from_list([0] * 16)
assert_equal(16, write_2bpp_graphic_to_block(source=source, target=target, offset=0, x=0, y=0, bit_offset=0))
assert_list_equal(target.to_list(),
[0b01010101,
0b10111010,
0b01100100,
0b11001111,
0b10100000,
0b10111101,
0b11100001,
0b01101011,
0b10110111,
0b00000111,
0b11111010,
0b01111101,
0b00110010,
0b11101100,
0b00110110,
0b10111100])
示例5: test_write_2bpp_graphic_to_block_offset_xy
# 需要導入模塊: from coilsnake.model.common.blocks import Block [as 別名]
# 或者: from coilsnake.model.common.blocks.Block import to_list [as 別名]
def test_write_2bpp_graphic_to_block_offset_xy():
source = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 2, 1, 2, 3, 2, 1, 2, 1],
[0, 0, 2, 3, 1, 0, 2, 3, 2, 2],
[0, 0, 3, 0, 3, 2, 2, 2, 0, 2],
[0, 0, 1, 3, 3, 0, 2, 0, 2, 3],
[0, 0, 1, 0, 1, 1, 0, 3, 3, 3],
[0, 0, 1, 3, 3, 3, 3, 2, 1, 2],
[0, 0, 2, 2, 3, 1, 2, 2, 1, 0],
[0, 0, 2, 0, 3, 3, 2, 3, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
target = Block()
target.from_list([0xff] * 18)
assert_equal(16, write_2bpp_graphic_to_block(source=source, target=target, offset=1, x=2, y=1, bit_offset=0))
assert_list_equal(target.to_list(),
[0xff,
0b01010101,
0b10111010,
0b01100100,
0b11001111,
0b10100000,
0b10111101,
0b11100001,
0b01101011,
0b10110111,
0b00000111,
0b11111010,
0b01111101,
0b00110010,
0b11101100,
0b00110110,
0b10111100,
0xff])
示例6: test_to_block
# 需要導入模塊: from coilsnake.model.common.blocks import Block [as 別名]
# 或者: from coilsnake.model.common.blocks.Block import to_list [as 別名]
def test_to_block(self):
block = Block()
block.from_list([0] * 2)
self.color.r = 248
self.color.g = 144
self.color.b = 16
self.color.to_block(block, 0)
assert_list_equal(block.to_list(), [0x5f, 0x0a])
示例7: test_to_block
# 需要導入模塊: from coilsnake.model.common.blocks import Block [as 別名]
# 或者: from coilsnake.model.common.blocks.Block import to_list [as 別名]
def test_to_block(self):
for test_case in TEST_CASES:
block_size = MapEnemyGroupTableEntry.to_block_size(test_case["value_rep"])
assert_equal(len(test_case["block_rep"]), block_size)
block = Block(size=block_size)
MapEnemyGroupTableEntry.to_block(block, 0, test_case["value_rep"])
assert_list_equal(test_case["block_rep"], block.to_list())
示例8: test_to_block
# 需要導入模塊: from coilsnake.model.common.blocks import Block [as 別名]
# 或者: from coilsnake.model.common.blocks.Block import to_list [as 別名]
def test_to_block(self):
block = Block()
block.from_list([0] * len(self.BLOCK_DATA))
table = Table(num_rows=len(self.TABLE_VALUES),
schema=self.TABLE_SCHEMA)
table.values = self.TABLE_VALUES
table.to_block(block, 0)
assert_list_equal(block.to_list(), self.BLOCK_DATA)
示例9: test_write_1bpp_graphic_to_block_rectangular_short
# 需要導入模塊: from coilsnake.model.common.blocks import Block [as 別名]
# 或者: from coilsnake.model.common.blocks.Block import to_list [as 別名]
def test_write_1bpp_graphic_to_block_rectangular_short():
source = [[0, 0, 0, 0, 0, 0, 1, 1],
[0, 1, 1, 1, 0, 0, 0, 0],
[0, 1, 0, 0, 1, 0, 0, 1],
[1, 1, 1, 1, 0, 0, 0, 0],
[0, 1, 0, 0, 1, 0, 1, 0],
[1, 1, 0, 0, 1, 0, 0, 0]]
target = Block()
target.from_list([0xeb] * 8)
target[0] = 42
assert_equal(6, write_1bpp_graphic_to_block(source, target, 2, x=0, y=0, height=6))
assert_list_equal(target.to_list(), [42, 0xeb,
0b00000011,
0b01110000,
0b01001001,
0b11110000,
0b01001010,
0b11001000])
示例10: test_write_1bpp_graphic_to_block_offset_source
# 需要導入模塊: from coilsnake.model.common.blocks import Block [as 別名]
# 或者: from coilsnake.model.common.blocks.Block import to_list [as 別名]
def test_write_1bpp_graphic_to_block_offset_source():
source = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 1, 1],
[0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 1, 0, 0, 1],
[0, 0, 1, 1, 1, 1, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 1, 0, 1, 0],
[0, 0, 1, 1, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 1, 1, 1, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
target = Block()
target.from_list([0] * 8)
assert_equal(8, write_1bpp_graphic_to_block(source, target, 0, x=2, y=1, height=8))
assert_list_equal(target.to_list(), [0b00000011,
0b01110000,
0b01001001,
0b11110000,
0b01001010,
0b11001000,
0b01110001,
0b00000001])
示例11: test_write_1bpp_graphic_to_block
# 需要導入模塊: from coilsnake.model.common.blocks import Block [as 別名]
# 或者: from coilsnake.model.common.blocks.Block import to_list [as 別名]
def test_write_1bpp_graphic_to_block():
source = [[0, 0, 0, 0, 0, 0, 1, 1],
[0, 1, 1, 1, 0, 0, 0, 0],
[0, 1, 0, 0, 1, 0, 0, 1],
[1, 1, 1, 1, 0, 0, 0, 0],
[0, 1, 0, 0, 1, 0, 1, 0],
[1, 1, 0, 0, 1, 0, 0, 0],
[0, 1, 1, 1, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 0, 1]]
target = Block()
target.from_list([32] * 10)
assert_equal(8, write_1bpp_graphic_to_block(source, target, 1, x=0, y=0, height=8))
assert_list_equal(target.to_list(), [32,
0b00000011,
0b01110000,
0b01001001,
0b11110000,
0b01001010,
0b11001000,
0b01110001,
0b00000001,
32])
示例12: test_read_1bpp_graphic_from_block_rectangular_tall
# 需要導入模塊: from coilsnake.model.common.blocks import Block [as 別名]
# 或者: from coilsnake.model.common.blocks.Block import to_list [as 別名]
def test_read_1bpp_graphic_from_block_rectangular_tall():
source = [[0, 0, 0, 0, 0, 0, 1, 1],
[0, 1, 1, 1, 0, 0, 0, 0],
[0, 1, 0, 0, 1, 0, 0, 1],
[1, 1, 1, 1, 0, 0, 0, 0],
[0, 1, 0, 0, 1, 0, 1, 0],
[1, 1, 0, 0, 1, 0, 0, 0],
[0, 1, 1, 1, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 0, 1],
[0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 0, 0, 0, 0],
[0, 0, 1, 0, 1, 0, 0, 0],
[0, 0, 1, 0, 1, 0, 0, 0],
[0, 1, 1, 0, 0, 0, 0, 0],
[1, 1, 1, 0, 0, 0, 0, 0],
[1, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 1]]
target = Block()
target.from_list([42, 11, 99, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 112, 113, 114, 115, 116, 12, 21])
assert_equal(16, write_1bpp_graphic_to_block(source, target, 3, x=0, y=0, height=16))
assert_list_equal(target.to_list(), [42, 11, 99,
0b00000011,
0b01110000,
0b01001001,
0b11110000,
0b01001010,
0b11001000,
0b01110001,
0b00000001,
0b00100000,
0b00110000,
0b00101000,
0b00101000,
0b01100000,
0b11100000,
0b11000000,
0b00000001,
12, 21])
示例13: TestBlock
# 需要導入模塊: from coilsnake.model.common.blocks import Block [as 別名]
# 或者: from coilsnake.model.common.blocks.Block import to_list [as 別名]
class TestBlock(BaseTestCase):
def setup(self):
self.block = Block()
def teardown(self):
del self.block
def test_baseline(self):
pass
def test_empty(self):
assert_equal(len(self.block), 0)
assert_equal(len(self.block.data), 0)
def test_from_file(self):
self.block.from_file(os.path.join(TEST_DATA_DIR, "binaries", "1kb_null.bin"))
assert_equal(len(self.block), 1024)
assert_list_equal(self.block.to_list(), [0] * 1024)
def test_from_file_unhappy(self):
# Attempt to load a directory
assert_raises(FileAccessError, self.block.from_file, TEST_DATA_DIR)
# Attempt to load a nonexistent file
assert_raises(FileAccessError, self.block.from_file, os.path.join(TEST_DATA_DIR, "doesnotexist.bin"))
# Attempt to load a file in a nonexistent directory
assert_raises(FileAccessError, self.block.from_file, os.path.join(TEST_DATA_DIR, "dne", "dne.bin"))
def test_from_list(self):
self.block.from_list([0, 1, 2, 3, 4, 5])
assert_equal(len(self.block), 6)
assert_list_equal(self.block.to_list(), [0, 1, 2, 3, 4, 5])
self.block.from_list([])
assert_equal(len(self.block), 0)
assert_list_equal(self.block.to_list(), [])
self.block.from_list([69])
assert_equal(len(self.block), 1)
assert_list_equal(self.block.to_list(), [69])
def test_getitem(self):
self.block.from_file(os.path.join(TEST_DATA_DIR, "binaries", "1kb_rand.bin"))
assert_equal(self.block[0], 0x25)
assert_equal(self.block[1023], 0x20)
assert_equal(self.block[0x3e3], 0xf4)
assert_equal(self.block[1023], self.block[-1])
assert_raises(OutOfBoundsError, self.block.__getitem__, 1024)
assert_raises(OutOfBoundsError, self.block.__getitem__, 9999)
def test_getitem_slice(self):
self.block.from_file(os.path.join(TEST_DATA_DIR, "binaries", "1kb_rand.bin"))
assert_is_instance(self.block[0:1], Block)
assert_list_equal(self.block[0:0].to_list(), [])
assert_list_equal(self.block[0x25c:0x25c].to_list(), [])
assert_list_equal(self.block[0x25c:0x25d].to_list(), [0xa0])
assert_list_equal(self.block[0x25c:0x25c + 5].to_list(), [0xa0, 0x0b, 0x71, 0x5d, 0x91])
assert_list_equal(self.block[0x25c:0x25c + 5].to_list(), [0xa0, 0x0b, 0x71, 0x5d, 0x91])
assert_list_equal(self.block[1022:1024].to_list(), [0x10, 0x20])
assert_raises(InvalidArgumentError, self.block.__getitem__, slice(0, -1))
assert_raises(OutOfBoundsError, self.block.__getitem__, slice(-2, -1))
assert_raises(InvalidArgumentError, self.block.__getitem__, slice(1024, 0))
assert_raises(InvalidArgumentError, self.block.__getitem__, slice(1024, -1))
assert_raises(InvalidArgumentError, self.block.__getitem__, slice(1022, 3))
def test_setitem(self):
self.block.from_file(os.path.join(TEST_DATA_DIR, "binaries", "1kb_rand.bin"))
self.block[1] = 0xaa
assert_equal(self.block[0], 0x25)
assert_equal(self.block[1], 0xaa)
assert_equal(self.block[2], 0x38)
assert_raises(OutOfBoundsError, self.block.__setitem__, 1024, 0xbb)
assert_raises(InvalidArgumentError, self.block.__setitem__, 5, 0x1234)
assert_raises(InvalidArgumentError, self.block.__setitem__, 0, 0x100)
assert_raises(InvalidArgumentError, self.block.__setitem__, 1, -1)
def test_setitem_slice(self):
self.block.from_file(os.path.join(TEST_DATA_DIR, "binaries", "1kb_rand.bin"))
assert_list_equal(self.block[0:3].to_list(), [0x25, 0x20, 0x38])
self.block[0:3] = [0xeb, 0x15, 0x66]
assert_list_equal(self.block[0:3].to_list(), [0xeb, 0x15, 0x66])
self.block[0:1024] = [5] * 1024
assert_equal(self.block[0:1024].to_list(), [5] * 1024)
assert_raises(InvalidArgumentError, self.block.__setitem__, slice(5, 0), [])
assert_raises(InvalidArgumentError, self.block.__setitem__, slice(55, 55), [])
assert_raises(OutOfBoundsError, self.block.__setitem__, slice(-1, 2), [])
assert_raises(OutOfBoundsError, self.block.__setitem__, slice(1, 1025), [0] * 1024)
assert_raises(OutOfBoundsError, self.block.__setitem__, slice(1024, 1025), [1])
assert_raises(InvalidArgumentError, self.block.__setitem__, slice(0, 1), [])
assert_raises(InvalidArgumentError, self.block.__setitem__, slice(0, 1), [1, 2, 3])
assert_raises(InvalidArgumentError, self.block.__setitem__, slice(0, 5), [1, 2])
#.........這裏部分代碼省略.........
示例14: test_write_4bpp_graphic_to_block
# 需要導入模塊: from coilsnake.model.common.blocks import Block [as 別名]
# 或者: from coilsnake.model.common.blocks.Block import to_list [as 別名]
def test_write_4bpp_graphic_to_block():
source = [[8, 1, 12, 9, 6, 5, 3, 2],
[11, 5, 8, 14, 1, 7, 15, 0],
[8, 13, 3, 7, 2, 0, 2, 3],
[10, 0, 4, 14, 7, 10, 11, 9],
[8, 8, 12, 9, 13, 12, 2, 6],
[11, 14, 14, 4, 14, 4, 10, 7],
[12, 2, 12, 8, 4, 15, 12, 14],
[10, 13, 12, 1, 10, 11, 11, 2]]
target = Block()
target.from_list([0] * 32)
assert_equal(32, write_4bpp_graphic_to_block(source=source, target=target, offset=0, x=0, y=0, bit_offset=0))
assert_list_equal(target.to_list(),
[
0b01010110,
0b00001011,
0b11001110,
0b10010110,
0b01110001,
0b00111011,
0b00001011,
0b10011110,
0b00011000,
0b00000011,
0b10000001,
0b11101011,
0b00000100,
0b01000101,
0b01010110,
0b10001111,
0b00101100,
0b10110000,
0b01010110,
0b10110010,
0b01010000,
0b11000000,
0b00111000,
0b10010111,
0b00101101,
0b11111100,
0b01111101,
0b11101010,
0b10101111,
0b10110111,
0b01100000,
0b11101110
])
示例15: test_write_asm_pointer
# 需要導入模塊: from coilsnake.model.common.blocks import Block [as 別名]
# 或者: from coilsnake.model.common.blocks.Block import to_list [as 別名]
def test_write_asm_pointer():
block = Block()
block.from_list([0xee] * 9)
write_asm_pointer(block, 1, 0xabcdef12)
assert_list_equal(block.to_list(), [0xee, 0xee, 0x12, 0xef, 0xee, 0xee, 0xee, 0xcd, 0xab])