Esempio n. 1
0
 def test_tag(self):
     be1 = BlockEntity('chest')
     be2 = be1.tag({'Lock': 'password'})
     self.assertEqual(be1.block_id, 'chest')
     self.assertEqual(be1.data_tag, CompoundDataTag())
     self.assertEqual(be2.block_id, 'chest')
     self.assertEqual(be2.data_tag, CompoundDataTag({'Lock': 'password'}))
 def test_breaking_values(self):
     dt = CompoundDataTag(key1='va lue',
                          key2='va$lue',
                          key3='minecraft:stone')
     self.assertEqual(
         dt.to_str(),
         '{key1:"va lue",key2:"va$lue",key3:"minecraft:stone"}')
Esempio n. 3
0
 def test_tag_overwrite(self):
     be1 = BlockEntity('chest',
                       data_tag=CompoundDataTag({'Lock': 'password'}))
     be2 = be1.tag({'Lock': 'guessme'})
     self.assertEqual(be1.block_id, 'chest')
     self.assertEqual(be1.data_tag, CompoundDataTag({'Lock': 'password'}))
     self.assertEqual(be2.block_id, 'chest')
     self.assertEqual(be2.data_tag, CompoundDataTag({'Lock': 'guessme'}))
Esempio n. 4
0
 def test_tag(self):
     i1 = Item('diamond')
     i2 = i1.tag({'Count': ByteDataTag(64)})
     self.assertEqual(i1.item_id, 'diamond')
     self.assertEqual(i1.data_tag, CompoundDataTag())
     self.assertEqual(i2.item_id, 'diamond')
     self.assertEqual(i2.data_tag,
                      CompoundDataTag({'Count': ByteDataTag(64)}))
 def test_breaking_keys(self):
     dt = CompoundDataTag({
         'ke$y': 'value1',
         'ke y': 'value2',
         'ke:y': 'value3'
     })
     self.assertEqual(dt.to_str(),
                      '{"ke$y":value1,"ke y":value2,"ke:y":value3}')
Esempio n. 6
0
    def test_everything(self):
        dt = CompoundDataTag(
            explicitbyte=ByteDataTag(True),
            explicitshort=ShortDataTag(12),
            explicitint=IntDataTag(123),
            explicitlong=LongDataTag(1234),
            explicitfloat=FloatDataTag(1234.5),
            explicitdouble=DoubleDataTag(1234.56),
            explicitstring=StringDataTag('hello'),
            explicitlist=ListDataTag([False, 9001, 'item']),
            explicitcompound=CompoundDataTag({
                'key1': True,
                'key2': 25565,
                'key3': 'stringvalue'
            }),
            anotherexplicitcompound=CompoundDataTag(key4=False,
                                                    key5=25566,
                                                    key6='stringvalue2'),
            implicitbyte=False,
            implicitint=321,
            implicitdouble=6543.21,
            implicitstring='goodbye',
            implicitlist=[True, 9002, 'anotheritem'],
            implicitcompound={
                'key7': True,
                'key8': 25567,
                'key9': 'stringvalue3'
            },
            anotherimplicitcompound=dict(key10=False,
                                         key11=25568,
                                         key12='stringvalue4'),
            breakingstring='breaking:string',
            quotedstring='quoted"string',
            innerbreakingstring=['inner:breakingstring'],
            innerquotedstring=['inner"quotedstring'],
            deepbreakingstring=[
                dict(one=[dict(two=[dict(three='deep:breakingstring')])])
            ],
            deepquotedstring=[
                dict(one=[dict(two=[dict(three='deep"quotedstring')])])
            ])
        self.assertEqual(
            dt.to_str(), r"""
{explicitbyte:1b,explicitshort:12s,explicitint:123,explicitlong:1234l,explicitfloat:1234.5f,explicitdouble:1234.56d,
explicitstring:hello,explicitlist:[0b,9001,item],explicitcompound:{key1:1b,key2:25565,key3:stringvalue},
anotherexplicitcompound:{key4:0b,key5:25566,key6:stringvalue2},implicitbyte:0b,implicitint:321,implicitdouble:6543.21d,
implicitstring:goodbye,implicitlist:[1b,9002,anotheritem],implicitcompound:{key7:1b,key8:25567,key9:stringvalue3},
anotherimplicitcompound:{key10:0b,key11:25568,key12:stringvalue4},breakingstring:"breaking:string",
quotedstring:"quoted\"string",innerbreakingstring:["inner:breakingstring"],innerquotedstring:["inner\"quotedstring"],
deepbreakingstring:[{one:[{two:[{three:"deep:breakingstring"}]}]}],
deepquotedstring:[{one:[{two:[{three:"deep\"quotedstring"}]}]}]}
""".replace('\n', ''))
Esempio n. 7
0
 def test_tag_more(self):
     be1 = BlockEntity('chest',
                       data_tag=CompoundDataTag({'Lock': 'password'}))
     be2 = be1.tag({'CustomName': 'Materials'})
     self.assertEqual(be1.block_id, 'chest')
     self.assertEqual(be1.data_tag, CompoundDataTag({'Lock': 'password'}))
     self.assertEqual(be2.block_id, 'chest')
     self.assertEqual(
         be2.data_tag,
         CompoundDataTag({
             'Lock': 'password',
             'CustomName': 'Materials'
         }))
Esempio n. 8
0
 def test_tag_more(self):
     i1 = Item('diamond',
               data_tag=CompoundDataTag({'Count': ByteDataTag(64)}))
     i2 = i1.tag({'Slot': ByteDataTag(8)})
     self.assertEqual(i1.item_id, 'diamond')
     self.assertEqual(i1.data_tag,
                      CompoundDataTag({'Count': ByteDataTag(64)}))
     self.assertEqual(i2.item_id, 'diamond')
     self.assertEqual(
         i2.data_tag,
         CompoundDataTag({
             'Count': ByteDataTag(64),
             'Slot': ByteDataTag(8)
         }))
 def test_all_conversions(self):
     dt = CompoundDataTag(mybyte=True,
                          myint=123456789,
                          mydouble=123.5,
                          mystring='somestring',
                          myemptylist=[],
                          myemptycompound={},
                          mycompound=dict(myinnerbyte=False,
                                          myinnerint=987654321,
                                          myinnerdouble=321.5,
                                          myinnerstring='someinnerstring',
                                          myinneremptycompound=dict()))
     self.assertEqual(
         dt.to_str(),
         '{mybyte:1b,myint:123456789,mydouble:123.5d,mystring:somestring,myemptylist:[],myemptycompound:{},'
         'mycompound:{myinnerbyte:0b,myinnerint:987654321,myinnerdouble:321.5d,myinnerstring:someinnerstring,'
         'myinneremptycompound:{}}}')
Esempio n. 10
0
 def test_empty_value(self):
     dt = CompoundDataTag(mykey='')
     self.assertEqual(dt.to_str(), '{mykey:""}')
Esempio n. 11
0
 def test_breaking_key_and_breaking_value(self):
     dt = CompoundDataTag({'my:key': 'some:value'})
     self.assertEqual(dt.to_str(), '{"my:key":"some:value"}')
Esempio n. 12
0
 def test_get(self):
     dt = CompoundDataTag(mykey='myvalue')
     self.assertEqual(dt['mykey'], StringDataTag('myvalue'))
Esempio n. 13
0
 def test_key_and_value(self):
     dt = CompoundDataTag(mykey='myvalue')
     self.assertEqual(dt.to_str(), '{mykey:myvalue}')
Esempio n. 14
0
 def test_nonempty_dict_and_kwargs_overwriting(self):
     dt = CompoundDataTag({'mykey': 'myvalue'}, mykey='anothervalue')
     self.assertEqual(dt.to_str(), '{mykey:anothervalue}')
Esempio n. 15
0
 def test_multi_empty_dicts(self):
     dt = CompoundDataTag({}, {})
     self.assertEqual(dt.to_str(), '{}')
Esempio n. 16
0
 def test_list_data_tag_conversion(self):
     dt = CompoundDataTag(mylist=[])
     self.assertEqual(dt.to_str(), '{mylist:[]}')
Esempio n. 17
0
 def test_byte_data_tag_conversion(self):
     dt = CompoundDataTag(mybyte=True)
     self.assertEqual(dt.to_str(), '{mybyte:1b}')
Esempio n. 18
0
 def test_int_data_tag_conversion(self):
     dt = CompoundDataTag(myint=123456789)
     self.assertEqual(dt.to_str(), '{myint:123456789}')
Esempio n. 19
0
 def test_double_data_tag_conversion(self):
     dt = CompoundDataTag(mydouble=123.5)
     self.assertEqual(dt.to_str(), '{mydouble:123.5d}')
Esempio n. 20
0
 def test_overwrite(self):
     dt = CompoundDataTag(mykey='myvalue')
     dt['mykey'] = 'anothervalue'
     self.assertEqual(dt['mykey'], StringDataTag('anothervalue'))
Esempio n. 21
0
 def test_deep_compound_data_tag_conversion(self):
     dt = CompoundDataTag(one=dict(two={'three': dict(four='five')}))
     self.assertEqual(dt.to_str(), '{one:{two:{three:{four:five}}}}')
Esempio n. 22
0
 def test_compound_data_tag_conversion(self):
     dt = CompoundDataTag(mycompound={})
     self.assertEqual(dt.to_str(), '{mycompound:{}}')
Esempio n. 23
0
 def test_questionable_keys(self):
     dt = CompoundDataTag({'ke_y': 'value1', 'k.e--+_y': 'value2'})
     self.assertEqual(dt.to_str(), '{ke_y:value1,k.e--+_y:value2}')
Esempio n. 24
0
 def test_default(self):
     dt = CompoundDataTag()
     self.assertEqual(dt.to_str(), '{}')
Esempio n. 25
0
 def test_questionable_values(self):
     dt = CompoundDataTag(key1='v__alue', key2='v.-_+alue')
     self.assertEqual(dt.to_str(), '{key1:v__alue,key2:v.-_+alue}')
Esempio n. 26
0
 def test_string_data_tag_conversion(self):
     dt = CompoundDataTag(mystring='hello')
     self.assertEqual(dt.to_str(), '{mystring:hello}')
Esempio n. 27
0
 def test_del_only(self):
     dt = CompoundDataTag(mykey='myvalue')
     self.assertEqual(dt.to_str(), '{mykey:myvalue}')
     del dt['mykey']
     self.assertEqual(dt.to_str(), '{}')
Esempio n. 28
0
 def test_len(self):
     dt = CompoundDataTag(mykey='myvalue', anotherkey='anothervalue')
     self.assertEqual(len(dt), 2)
Esempio n. 29
0
 def __init__(self,
              block_id: str,
              block_state: Mapping = None,
              data_tag: Mapping = None):
     super().__init__(block_id=block_id, block_state=block_state)
     self.data_tag: CompoundDataTag = CompoundDataTag.sift(data_tag, {})
Esempio n. 30
0
 def test_del_with_remaining(self):
     dt = CompoundDataTag(mykey='myvalue', anotherkey='anothervalue')
     self.assertEqual(dt.to_str(),
                      '{mykey:myvalue,anotherkey:anothervalue}')
     del dt['mykey']
     self.assertEqual(dt.to_str(), '{anotherkey:anothervalue}')