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"}')
 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}')
示例#3
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', ''))
 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:{}}}')
 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}')
 def test_empty_value(self):
     dt = CompoundDataTag(mykey='')
     self.assertEqual(dt.to_str(), '{mykey:""}')
 def test_breaking_key_and_breaking_value(self):
     dt = CompoundDataTag({'my:key': 'some:value'})
     self.assertEqual(dt.to_str(), '{"my:key":"some:value"}')
 def test_key_and_value(self):
     dt = CompoundDataTag(mykey='myvalue')
     self.assertEqual(dt.to_str(), '{mykey:myvalue}')
 def test_nonempty_dict_and_kwargs_overwriting(self):
     dt = CompoundDataTag({'mykey': 'myvalue'}, mykey='anothervalue')
     self.assertEqual(dt.to_str(), '{mykey:anothervalue}')
 def test_multi_empty_dicts(self):
     dt = CompoundDataTag({}, {})
     self.assertEqual(dt.to_str(), '{}')
 def test_double_data_tag_conversion(self):
     dt = CompoundDataTag(mydouble=123.5)
     self.assertEqual(dt.to_str(), '{mydouble:123.5d}')
 def test_value_with_quotes(self):
     dt = CompoundDataTag(mykey='my"value')
     self.assertEqual(dt.to_str(), r'{mykey:"my\"value"}')
 def test_byte_data_tag_conversion(self):
     dt = CompoundDataTag(mybyte=True)
     self.assertEqual(dt.to_str(), '{mybyte:1b}')
 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}}}}')
 def test_compound_data_tag_conversion(self):
     dt = CompoundDataTag(mycompound={})
     self.assertEqual(dt.to_str(), '{mycompound:{}}')
 def test_list_data_tag_conversion(self):
     dt = CompoundDataTag(mylist=[])
     self.assertEqual(dt.to_str(), '{mylist:[]}')
 def test_string_data_tag_conversion(self):
     dt = CompoundDataTag(mystring='hello')
     self.assertEqual(dt.to_str(), '{mystring:hello}')
 def test_questionable_values(self):
     dt = CompoundDataTag(key1='v__alue', key2='v.-_+alue')
     self.assertEqual(dt.to_str(), '{key1:v__alue,key2:v.-_+alue}')
 def test_default(self):
     dt = CompoundDataTag()
     self.assertEqual(dt.to_str(), '{}')
 def test_del_only(self):
     dt = CompoundDataTag(mykey='myvalue')
     self.assertEqual(dt.to_str(), '{mykey:myvalue}')
     del dt['mykey']
     self.assertEqual(dt.to_str(), '{}')
 def test_int_data_tag_conversion(self):
     dt = CompoundDataTag(myint=123456789)
     self.assertEqual(dt.to_str(), '{myint:123456789}')
 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}')
 def test_key_with_quotes(self):
     dt = CompoundDataTag({'my"key': 'myvalue'})
     self.assertEqual(dt.to_str(), r'{"my\"key":myvalue}')