def test_state(self): b1 = Block('piston') b2 = b1.state(facing='up') self.assertEqual(b1.block_id, 'piston') self.assertEqual(b1.block_state, BlockState()) self.assertEqual(b2.block_id, 'piston') self.assertEqual(b2.block_state, BlockState(facing='up'))
def test_setitem_bad_value_str(self): bs = BlockState() with self.assertRaises(ValueError): bs['goodkey'] = 'bad value'
def test_setitem_bad_key_obj(self): bs = BlockState() with self.assertRaises(KeyError): bs[{'bad', 'obj'}] = 'goodvalue'
def test_block_state_from_dict(self): b = Block('piston', dict(facing='up')) self.assertEqual(b.block_state, BlockState(facing='up'))
def test_str_with_str_values(self): bs = BlockState(half='bottom', variant='quartz') self.assertEqual( set(str(bs).split(',')), set('half=bottom,variant=quartz'.split(',')))
def test_int_value(self): bs = BlockState(age=4) self.assertEqual(bs['age'], 4)
def test_bool_false(self): bs = BlockState(powered=False) self.assertEqual(bs['powered'], False)
def test_eq(self): bs = BlockState(color='blue') self.assertEqual(bs, BlockState(color='blue'))
def test_getitem(self): bs = BlockState(half='bottom', variant='quartz') self.assertEqual(bs['half'], 'bottom') self.assertEqual(bs['variant'], 'quartz')
def __init__(self, block_id: str, block_state: Mapping = None): self.block_id: str = block_id self.block_state: BlockState = BlockState.sift(block_state, {})
def test_with_id_and_block_state_and_data_tag(self): be = BlockEntity('chest', BlockState(facing='north'), CompoundDataTag(lock='password')) self.assertEqual(be.block_id, 'chest') self.assertEqual(be.block_state['facing'], 'north') self.assertEqual(be.data_tag['lock'], StringDataTag('password'))
def test_with_id_and_block_state(self): be = BlockEntity('chest', BlockState(facing='north')) self.assertEqual(be.block_id, 'chest') self.assertEqual(be.block_state['facing'], 'north')
def test_block_state_from_braces(self): b = Block('piston', {'facing': 'up'}) self.assertEqual(b.block_state, BlockState(facing='up'))
def test_setitem_bad_value_obj(self): bs = BlockState() with self.assertRaises(ValueError): bs['goodkey'] = {'bad', 'obj'}
def test_len_0(self): bs0 = BlockState() self.assertEqual(len(bs0), 0)
def test_set_then_get(self): bs = BlockState() bs['color'] = 'blue' self.assertEqual(bs['color'], 'blue')
def test_len_1(self): bs1 = BlockState(color='blue') self.assertEqual(len(bs1), 1)
def test_overwrite(self): bs = BlockState(color='blue') self.assertEqual(bs['color'], 'blue') bs['color'] = 'red' self.assertEqual(bs['color'], 'red')
def test_len_2(self): bs2 = BlockState(half='bottom', variant='quartz') self.assertEqual(len(bs2), 2)
def test_bool_true(self): bs = BlockState(powered=True) self.assertEqual(bs['powered'], True)
def test_delitem(self): bs = BlockState(half='bottom', variant='quartz') self.assertEqual(bs['variant'], 'quartz') del bs['variant'] with self.assertRaises(KeyError): shouldfail = bs['variant']
def test_str_default(self): bs = BlockState() self.assertEqual(str(bs), 'default')
def test_setitem_bad_key_str(self): bs = BlockState() with self.assertRaises(KeyError): bs['bad key'] = 'goodvalue'
def test_str_with_all_values(self): bs = BlockState(powered=True, age=7, color='green') self.assertEqual( set(str(bs).split(',')), set('powered=true,age=7,color=green'.split(',')))
def test_block_with_id_and_block_state(self): b = Block('piston', BlockState(facing='up')) self.assertEqual(b.block_id, 'piston') self.assertEqual(b.block_state, BlockState(facing='up'))