本文整理汇总了Python中pvl.loads函数的典型用法代码示例。如果您正苦于以下问题:Python loads函数的具体用法?Python loads怎么用?Python loads使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了loads函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_units
def test_units():
label = pvl.loads("""
foo = 42 <beards>
g = 9.8 <m/s>
list = (1, 2, 3) <numbers>
cool = (1 <number>)
End
""")
assert isinstance(label['foo'], Units)
assert label['foo'].value == 42
assert label['foo'].units == 'beards'
assert isinstance(label['g'], Units)
assert label['g'].value == 9.8
assert label['g'].units == 'm/s'
assert isinstance(label['list'], Units)
assert isinstance(label['list'].value, list)
assert label['list'].units == 'numbers'
assert isinstance(label['cool'], list)
assert isinstance(label['cool'][0], Units)
assert label['cool'][0].value == 1
assert label['cool'][0].units == 'number'
with pytest.raises(pvl.decoder.ParseError):
pvl.loads(b'foo = bar <')
示例2: test_groups
def test_groups():
label = pvl.loads("""
Group = test_group
foo = bar
Object = embedded_object
foo = bar
End_Object
Group = embedded_group
foo = bar
End_Group
End_Group
End
""")
test_group = label['test_group']
assert isinstance(test_group, LabelGroup)
assert test_group['foo'] == 'bar'
embedded_object = test_group['embedded_object']
assert isinstance(embedded_object, LabelObject)
assert embedded_object['foo'] == 'bar'
embedded_group = test_group['embedded_group']
assert isinstance(embedded_group, LabelGroup)
assert embedded_group['foo'] == 'bar'
with pytest.raises(pvl.decoder.ParseError):
pvl.loads("""
BEGIN_GROUP = foo
END_GROUP = bar
""")
示例3: test_comments
def test_comments():
label = pvl.loads("""
/* comment on line */
# here is a line comment
/* here is a multi-
line comment */
foo = bar /* comment at end of line */
weird/* in the */=/*middle*/comments
baz = bang # end line comment
End
""")
assert len(label) == 3
assert isinstance(label['foo'], six.text_type)
assert label['foo'] == 'bar'
assert isinstance(label['foo'], six.text_type)
assert label['weird'] == 'comments'
assert isinstance(label['foo'], six.text_type)
assert label['baz'] == 'bang'
with pytest.raises(pvl.decoder.ParseError):
pvl.loads(b'/*')
示例4: test_assignment
def test_assignment():
label = pvl.loads('foo=bar')
assert isinstance(label, Label)
assert label['foo'] == 'bar'
label = pvl.loads('Group_Foo=bar')
assert isinstance(label, Label)
assert label['Group_Foo'] == 'bar'
示例5: test_special_values
def test_special_values():
module = pvl.PVLModule([
('bool_true', True),
('bool_false', False),
('null', None),
])
assert module == pvl.loads(pvl.dumps(module))
encoder = pvl.encoder.IsisCubeLabelEncoder
assert module == pvl.loads(pvl.dumps(module, cls=encoder))
encoder = pvl.encoder.PDSLabelEncoder
assert module == pvl.loads(pvl.dumps(module, cls=encoder))
示例6: test_special_strings
def test_special_strings():
module = pvl.PVLModule([
('single_quote', "'"),
('double_quote', '"'),
('mixed_quotes', '"\''),
])
assert module == pvl.loads(pvl.dumps(module))
encoder = pvl.encoder.IsisCubeLabelEncoder
assert module == pvl.loads(pvl.dumps(module, cls=encoder))
encoder = pvl.encoder.PDSLabelEncoder
assert module == pvl.loads(pvl.dumps(module, cls=encoder))
示例7: test_dates
def test_dates():
label = pvl.loads("""
date1 = 1990-07-04
date2 = 1990-158
date3 = 2001-001
time1 = 12:00
time_s = 12:00:45
time_s_float = 12:00:45.4571
time_tz1 = 15:24:12Z
time_tz2 = 01:12:22+07
time_tz3 = 01:12:22+7
time_tz4 = 01:10:39.4575+07
datetime1 = 1990-07-04T12:00
datetime2 = 1990-158T15:24:12Z
datetime3 = 2001-001T01:10:39+7
datetime4 = 2001-001T01:10:39.457591+7
End
""")
assert isinstance(label['date1'], datetime.date)
assert label['date1'] == datetime.date(1990, 7, 4)
assert isinstance(label['date2'], datetime.date)
assert label['date2'] == datetime.date(1990, 6, 7)
assert isinstance(label['date3'], datetime.date)
assert label['date3'] == datetime.date(2001, 1, 1)
assert isinstance(label['time1'], datetime.time)
assert label['time1'] == datetime.time(12)
assert isinstance(label['time_s'], datetime.time)
assert label['time_s'] == datetime.time(12, 0, 45)
assert isinstance(label['time_s_float'], datetime.time)
assert label['time_s_float'] == datetime.time(12, 0, 45, 457100)
assert isinstance(label['time_tz1'], datetime.time)
assert label['time_tz1'] == datetime.time(15, 24, 12, tzinfo=pytz.utc)
assert isinstance(label['time_tz2'], datetime.time)
assert label['time_tz2'] == datetime.time(1, 12, 22, tzinfo=pytz.FixedOffset(420)) # noqa
assert isinstance(label['time_tz3'], datetime.time)
assert label['time_tz3'] == datetime.time(1, 12, 22, tzinfo=pytz.FixedOffset(420)) # noqa
assert isinstance(label['time_tz4'], datetime.time)
assert label['time_tz4'] == datetime.time(1, 10, 39, 457500, pytz.FixedOffset(420)) # noqa
assert isinstance(label['datetime1'], datetime.datetime)
assert label['datetime1'] == datetime.datetime(1990, 7, 4, 12)
assert isinstance(label['datetime2'], datetime.datetime)
assert label['datetime2'] == datetime.datetime(1990, 6, 7, 15, 24, 12, tzinfo=pytz.utc) # noqa
assert isinstance(label['datetime3'], datetime.datetime)
assert label['datetime3'] == datetime.datetime(2001, 1, 1, 1, 10, 39, tzinfo=pytz.FixedOffset(420)) # noqa
assert isinstance(label['datetime4'], datetime.datetime)
assert label['datetime4'] == datetime.datetime(2001, 1, 1, 1, 10, 39, 457591, pytz.FixedOffset(420)) # noqa
示例8: test_floats
def test_floats():
label = pvl.loads("""
float = 1.0
float_no_decimal = 2.
float_no_whole = .3
float_leading_zero = 0.5
positive_float = +2.0
negative_float = -1.0
invalid_float = 1.2.3
End
""")
assert isinstance(label['float'], float)
assert label['float'] == 1.0
assert isinstance(label['float_no_decimal'], float)
assert label['float_no_decimal'] == 2.0
assert isinstance(label['float_no_whole'], float)
assert label['float_no_whole'] == 0.3
assert isinstance(label['float_leading_zero'], float)
assert label['float_leading_zero'] == 0.5
assert isinstance(label['positive_float'], float)
assert label['positive_float'] == 2.0
assert isinstance(label['negative_float'], float)
assert label['negative_float'] == -1.0
assert isinstance(label['invalid_float'], six.text_type)
assert label['invalid_float'] == '1.2.3'
示例9: test_groups
def test_groups():
label = pvl.loads("""
Group = test_group
foo = bar
Object = embedded_object
foo = bar
End_Object
Group = embedded_group
foo = bar
End_Group
End_Group
End
""")
test_group = label['test_group']
assert isinstance(test_group, LabelGroup)
assert test_group['foo'] == 'bar'
embedded_object = test_group['embedded_object']
assert isinstance(embedded_object, LabelObject)
assert embedded_object['foo'] == 'bar'
embedded_group = test_group['embedded_group']
assert isinstance(embedded_group, LabelGroup)
assert embedded_group['foo'] == 'bar'
示例10: test_linewrap
def test_linewrap():
label = pvl.loads("""
foo = bar-
baz
End
""")
assert label['foo'] == 'barbaz'
示例11: test_hex
def test_hex():
label = pvl.loads("""
hex_number_upper = 16#100A#
hex_number_lower = 16#100b#
positive_hex_number = +16#100A#
negative_hex_number = -16#100A#
End
""")
assert isinstance(label['hex_number_upper'], int)
assert label['hex_number_upper'] == 4106
assert isinstance(label['hex_number_lower'], int)
assert label['hex_number_lower'] == 4107
assert isinstance(label['positive_hex_number'], int)
assert label['positive_hex_number'] == 4106
assert isinstance(label['negative_hex_number'], int)
assert label['negative_hex_number'] == -4106
with pytest.raises(pvl.decoder.ParseError):
pvl.loads('empty = 16##')
with pytest.raises(pvl.decoder.ParseError):
pvl.loads('hex_number_upper = 16#100A')
with pytest.raises(pvl.decoder.ParseError):
pvl.loads('hex_number_upper = 16#100AZ#')
示例12: test_octal
def test_octal():
label = pvl.loads("""
octal_number = 8#0107#
positive_octal_number = +8#0107#
negative_octal_number = -8#0107#
End
""")
assert isinstance(label['octal_number'], int)
assert label['octal_number'] == 71
assert isinstance(label['positive_octal_number'], int)
assert label['positive_octal_number'] == 71
assert isinstance(label['negative_octal_number'], int)
assert label['negative_octal_number'] == -71
with pytest.raises(pvl.decoder.ParseError):
pvl.loads('empty = 8##')
with pytest.raises(pvl.decoder.ParseError):
pvl.loads('octal_number = 8#0107')
with pytest.raises(pvl.decoder.ParseError):
pvl.loads('octal_number = 8#01079#')
示例13: test_binary
def test_binary():
label = pvl.loads("""
binary_number = 2#0101#
positive_binary_number = +2#0101#
negative_binary_number = -2#0101#
End
""")
assert isinstance(label['binary_number'], int)
assert label['binary_number'] == 5
assert isinstance(label['positive_binary_number'], int)
assert label['positive_binary_number'] == 5
assert isinstance(label['negative_binary_number'], int)
assert label['negative_binary_number'] == -5
with pytest.raises(pvl.decoder.ParseError):
pvl.loads('empty = 2##')
with pytest.raises(pvl.decoder.ParseError):
pvl.loads('binary_number = 2#0101')
with pytest.raises(pvl.decoder.ParseError):
pvl.loads('binary_number = 2#01014201#')
示例14: test_quoated_strings
def test_quoated_strings():
module = pvl.PVLModule([
('int_like', "123"),
('float_like', '.2'),
('date', '1987-02-25'),
('time', '03:04:05'),
('datetime', '1987-02-25T03:04:05'),
('keyword', 'END'),
('restricted_chars', '&<>\'{},[]=!#()%";|'),
('restricted_seq', '/**/'),
])
assert module == pvl.loads(pvl.dumps(module))
encoder = pvl.encoder.IsisCubeLabelEncoder
assert module == pvl.loads(pvl.dumps(module, cls=encoder))
encoder = pvl.encoder.PDSLabelEncoder
assert module == pvl.loads(pvl.dumps(module, cls=encoder))
示例15: test_quotes
def test_quotes():
label = pvl.loads("""
foo = 'bar'
empty = ''
space = ' test '
double = "double'quotes"
single = 'single"quotes'
mixed = 'mixed"\\'quotes'
number = '123'
date = '1918-05-11'
multiline = 'this is a
multi-line string'
continuation = "The planet Jupi-
ter is very big"
formating = "\\n\\t\\f\\v\\\\\\n\\t\\f\\v\\\\"
End
""")
assert isinstance(label['foo'], six.text_type)
assert label['foo'] == 'bar'
assert isinstance(label['empty'], six.text_type)
assert label['empty'] == ''
assert isinstance(label['space'], six.text_type)
assert label['space'] == 'test'
assert isinstance(label['double'], six.text_type)
assert label['double'] == "double'quotes"
assert isinstance(label['single'], six.text_type)
assert label['single'] == 'single"quotes'
assert isinstance(label['single'], six.text_type)
assert label['mixed'] == 'mixed"\'quotes'
assert isinstance(label['number'], six.text_type)
assert label['number'] == '123'
assert isinstance(label['date'], six.text_type)
assert label['date'] == '1918-05-11'
assert isinstance(label['multiline'], six.text_type)
assert label['multiline'] == 'this is a multi-line string'
assert isinstance(label['continuation'], six.text_type)
assert label['continuation'] == 'The planet Jupiter is very big'
assert isinstance(label['formating'], six.text_type)
assert label['formating'] == '\n\t\f\v\\\n\t\f\v\\'
with pytest.raises(pvl.decoder.ParseError):
pvl.loads('foo = "bar')
with pytest.raises(pvl.decoder.ParseError):
pvl.loads("foo = 'bar")
with pytest.raises(pvl.decoder.ParseError):
pvl.loads("foo = '\\bar'")