Example #1
0
 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'))
Example #2
0
 def test_setitem_bad_value_str(self):
     bs = BlockState()
     with self.assertRaises(ValueError):
         bs['goodkey'] = 'bad value'
Example #3
0
 def test_setitem_bad_key_obj(self):
     bs = BlockState()
     with self.assertRaises(KeyError):
         bs[{'bad', 'obj'}] = 'goodvalue'
Example #4
0
 def test_block_state_from_dict(self):
     b = Block('piston', dict(facing='up'))
     self.assertEqual(b.block_state, BlockState(facing='up'))
Example #5
0
 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(',')))
Example #6
0
 def test_int_value(self):
     bs = BlockState(age=4)
     self.assertEqual(bs['age'], 4)
Example #7
0
 def test_bool_false(self):
     bs = BlockState(powered=False)
     self.assertEqual(bs['powered'], False)
Example #8
0
 def test_eq(self):
     bs = BlockState(color='blue')
     self.assertEqual(bs, BlockState(color='blue'))
Example #9
0
 def test_getitem(self):
     bs = BlockState(half='bottom', variant='quartz')
     self.assertEqual(bs['half'], 'bottom')
     self.assertEqual(bs['variant'], 'quartz')
Example #10
0
 def __init__(self, block_id: str, block_state: Mapping = None):
     self.block_id: str = block_id
     self.block_state: BlockState = BlockState.sift(block_state, {})
Example #11
0
 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'))
Example #12
0
 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')
Example #13
0
 def test_block_state_from_braces(self):
     b = Block('piston', {'facing': 'up'})
     self.assertEqual(b.block_state, BlockState(facing='up'))
Example #14
0
 def test_setitem_bad_value_obj(self):
     bs = BlockState()
     with self.assertRaises(ValueError):
         bs['goodkey'] = {'bad', 'obj'}
Example #15
0
 def test_len_0(self):
     bs0 = BlockState()
     self.assertEqual(len(bs0), 0)
Example #16
0
 def test_set_then_get(self):
     bs = BlockState()
     bs['color'] = 'blue'
     self.assertEqual(bs['color'], 'blue')
Example #17
0
 def test_len_1(self):
     bs1 = BlockState(color='blue')
     self.assertEqual(len(bs1), 1)
Example #18
0
 def test_overwrite(self):
     bs = BlockState(color='blue')
     self.assertEqual(bs['color'], 'blue')
     bs['color'] = 'red'
     self.assertEqual(bs['color'], 'red')
Example #19
0
 def test_len_2(self):
     bs2 = BlockState(half='bottom', variant='quartz')
     self.assertEqual(len(bs2), 2)
Example #20
0
 def test_bool_true(self):
     bs = BlockState(powered=True)
     self.assertEqual(bs['powered'], True)
Example #21
0
 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']
Example #22
0
 def test_str_default(self):
     bs = BlockState()
     self.assertEqual(str(bs), 'default')
Example #23
0
 def test_setitem_bad_key_str(self):
     bs = BlockState()
     with self.assertRaises(KeyError):
         bs['bad key'] = 'goodvalue'
Example #24
0
 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(',')))
Example #25
0
 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'))