当前位置: 首页>>代码示例>>Python>>正文


Python tomlkit.parse方法代码示例

本文整理汇总了Python中tomlkit.parse方法的典型用法代码示例。如果您正苦于以下问题:Python tomlkit.parse方法的具体用法?Python tomlkit.parse怎么用?Python tomlkit.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tomlkit的用法示例。


在下文中一共展示了tomlkit.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_adding_an_element_to_existing_table_with_ws_remove_ws

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import parse [as 别名]
def test_adding_an_element_to_existing_table_with_ws_remove_ws():
    content = """[foo]

[foo.bar]

"""

    doc = parse(content)
    doc["foo"]["int"] = 34

    expected = """[foo]
int = 34

[foo.bar]

"""

    assert expected == doc.as_string() 
开发者ID:sdispater,项目名称:tomlkit,代码行数:20,代码来源:test_toml_document.py

示例2: test_toml_document_without_super_tables

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import parse [as 别名]
def test_toml_document_without_super_tables():
    content = """[tool.poetry]
name = "foo"
"""

    doc = parse(content)
    assert "tool" in doc
    assert "poetry" in doc["tool"]

    assert doc["tool"]["poetry"]["name"] == "foo"

    doc["tool"]["poetry"]["name"] = "bar"

    assert (
        doc.as_string()
        == """[tool.poetry]
name = "bar"
"""
    )

    d = {}
    d.update(doc)

    assert "tool" in d 
开发者ID:sdispater,项目名称:tomlkit,代码行数:26,代码来源:test_toml_document.py

示例3: test_toml_document_with_dotted_keys

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import parse [as 别名]
def test_toml_document_with_dotted_keys(example):
    content = example("0.5.0")

    doc = parse(content)

    assert "physical" in doc
    assert "color" in doc["physical"]
    assert "shape" in doc["physical"]
    assert doc["physical"]["color"] == "orange"
    assert doc["physical"]["shape"] == "round"

    assert "site" in doc
    assert "google.com" in doc["site"]
    assert doc["site"]["google.com"]

    assert doc["a"]["b"]["c"] == 1
    assert doc["a"]["b"]["d"] == 2 
开发者ID:sdispater,项目名称:tomlkit,代码行数:19,代码来源:test_toml_document.py

示例4: test_document_with_new_sub_table_after_other_table_delete

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import parse [as 别名]
def test_document_with_new_sub_table_after_other_table_delete():
    content = """[foo]
name = "Bar"

[bar]
name = "Baz"

[foo.baz]
name = "Test 1"
"""

    doc = parse(content)

    del doc["foo"]

    assert (
        doc.as_string()
        == """[bar]
name = "Baz"

"""
    ) 
开发者ID:sdispater,项目名称:tomlkit,代码行数:24,代码来源:test_toml_document.py

示例5: test_document_with_new_sub_table_after_other_table_replace

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import parse [as 别名]
def test_document_with_new_sub_table_after_other_table_replace():
    content = """[foo]
name = "Bar"

[bar]
name = "Baz"

[foo.baz]
name = "Test 1"
"""

    doc = parse(content)

    doc["foo"] = {"a": "b"}

    assert (
        doc.as_string()
        == """[foo]
a = "b"

[bar]
name = "Baz"

"""
    ) 
开发者ID:sdispater,项目名称:tomlkit,代码行数:27,代码来源:test_toml_document.py

示例6: test_inserting_after_element_with_no_new_line_adds_a_new_line

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import parse [as 别名]
def test_inserting_after_element_with_no_new_line_adds_a_new_line():
    doc = parse("foo = 10")
    doc["bar"] = 11

    expected = """foo = 10
bar = 11
"""

    assert expected == doc.as_string()

    doc = parse("# Comment")
    doc["bar"] = 11

    expected = """# Comment
bar = 11
"""

    assert expected == doc.as_string() 
开发者ID:sdispater,项目名称:tomlkit,代码行数:20,代码来源:test_toml_document.py

示例7: test_toml_document_has_always_a_new_line_after_table_header

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import parse [as 别名]
def test_toml_document_has_always_a_new_line_after_table_header():
    content = """[section.sub]"""

    doc = parse(content)
    assert doc.as_string() == """[section.sub]"""

    doc["section"]["sub"]["foo"] = "bar"
    assert (
        doc.as_string()
        == """[section.sub]
foo = "bar"
"""
    )

    del doc["section"]["sub"]["foo"]

    assert doc.as_string() == """[section.sub]""" 
开发者ID:sdispater,项目名称:tomlkit,代码行数:19,代码来源:test_toml_document.py

示例8: test_integers_behave_like_ints

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import parse [as 别名]
def test_integers_behave_like_ints():
    i = item(34)

    assert i == 34
    assert i.as_string() == "34"

    i += 1
    assert i == 35
    assert i.as_string() == "35"

    i -= 2
    assert i == 33
    assert i.as_string() == "33"

    doc = parse("int = +34")
    doc["int"] += 1

    assert doc.as_string() == "int = +35" 
开发者ID:sdispater,项目名称:tomlkit,代码行数:20,代码来源:test_items.py

示例9: test_datetimes_behave_like_datetimes

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import parse [as 别名]
def test_datetimes_behave_like_datetimes():
    i = item(datetime(2018, 7, 22, 12, 34, 56))

    assert i == datetime(2018, 7, 22, 12, 34, 56)
    assert i.as_string() == "2018-07-22T12:34:56"

    i += timedelta(days=1)
    assert i == datetime(2018, 7, 23, 12, 34, 56)
    assert i.as_string() == "2018-07-23T12:34:56"

    i -= timedelta(days=2)
    assert i == datetime(2018, 7, 21, 12, 34, 56)
    assert i.as_string() == "2018-07-21T12:34:56"

    doc = parse("dt = 2018-07-22T12:34:56-05:00")
    doc["dt"] += timedelta(days=1)

    assert doc.as_string() == "dt = 2018-07-23T12:34:56-05:00" 
开发者ID:sdispater,项目名称:tomlkit,代码行数:20,代码来源:test_items.py

示例10: test_dates_behave_like_dates

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import parse [as 别名]
def test_dates_behave_like_dates():
    i = item(date(2018, 7, 22))

    assert i == date(2018, 7, 22)
    assert i.as_string() == "2018-07-22"

    i += timedelta(days=1)
    assert i == datetime(2018, 7, 23)
    assert i.as_string() == "2018-07-23"

    i -= timedelta(days=2)
    assert i == date(2018, 7, 21)
    assert i.as_string() == "2018-07-21"

    doc = parse("dt = 2018-07-22 # Comment")
    doc["dt"] += timedelta(days=1)

    assert doc.as_string() == "dt = 2018-07-23 # Comment" 
开发者ID:sdispater,项目名称:tomlkit,代码行数:20,代码来源:test_items.py

示例11: test_strings_behave_like_strs

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import parse [as 别名]
def test_strings_behave_like_strs():
    i = item("foo")

    assert i == "foo"
    assert i.as_string() == '"foo"'

    i += " bar"
    assert i == "foo bar"
    assert i.as_string() == '"foo bar"'

    i += " é"
    assert i == "foo bar é"
    assert i.as_string() == '"foo bar é"'

    doc = parse('str = "foo" # Comment')
    doc["str"] += " bar"

    assert doc.as_string() == 'str = "foo bar" # Comment' 
开发者ID:sdispater,项目名称:tomlkit,代码行数:20,代码来源:test_items.py

示例12: test_booleans_comparison

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import parse [as 别名]
def test_booleans_comparison():
    boolean = Bool(True, Trivia())

    assert boolean

    boolean = Bool(False, Trivia())

    assert not boolean

    s = """[foo]
value = false
"""

    content = parse(s)

    assert {"foo": {"value": False}} == content
    assert {"value": False} == content["foo"] 
开发者ID:sdispater,项目名称:tomlkit,代码行数:19,代码来源:test_items.py

示例13: test_dump

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import parse [as 别名]
def test_dump(requirements_path: Path):
    converter = PoetryConverter()
    resolver = converter.load_resolver(requirements_path / 'poetry.toml')
    reqs = Requirement.from_graph(graph=resolver.graph, lock=False)
    assert len(reqs) > 2
    content = converter.dumps(reqs=reqs, project=resolver.graph.metainfo)
    assert 'requests = ' in content
    assert 'extras = ["security"]' in content
    assert 'toml = "==0.*,>=0.9.0"' in content

    assert 'https://github.com/django/django.git' in content

    parsed = tomlkit.parse(content)['tool']['poetry']
    assert '>=0.9' in parsed['dependencies']['toml']
    assert '>=2.13' in parsed['dependencies']['requests']['version']
    assert {'security'} == set(parsed['dependencies']['requests']['extras'])

    assert parsed['dependencies']['pathlib2']['allows-prereleases'] is True
    assert parsed['dependencies']['pathlib2']['python'] == '==2.7.*,>=2.7.0'

    assert parsed['dependencies']['django']['git'] == 'https://github.com/django/django.git'
    assert parsed['dependencies']['django']['rev'] == '1.11.4'

    assert 'pytest' in parsed['dev-dependencies'] 
开发者ID:dephell,项目名称:dephell,代码行数:26,代码来源:test_poetry.py

示例14: test_preserve_repositories

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import parse [as 别名]
def test_preserve_repositories():
    content = dedent("""
        [tool.poetry]
        name = "test"
        version = "1.2.3"

        [tool.poetry.dependencies]
        python = "*"

        [[tool.poetry.source]]
        name = "pypi"
        url = "https://pypi.org/pypi"
    """)
    converter = PoetryConverter()
    root = converter.loads(content)
    new_content = converter.dumps(reqs=[], project=root)
    parsed = tomlkit.parse(content)['tool']['poetry']
    new_parsed = tomlkit.parse(new_content)['tool']['poetry']
    assert parsed['source'] == new_parsed['source']
    assert parsed == new_parsed 
开发者ID:dephell,项目名称:dephell,代码行数:22,代码来源:test_poetry.py

示例15: test_create

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import parse [as 别名]
def test_create(temp_path: Path):
    config = temp_path / 'pyproject.toml'
    task = GenerateConfigCommand(
        argv=['--config', str(config), '--project', str(temp_path)],
    )
    result = task()
    assert result is True
    assert config.exists()
    assert config.is_file()
    content = config.read_text()
    parsed = tomlkit.parse(content)

    assert '[tool.dephell.example]' in content
    assert 'from = {format = "pip"' in content

    parsed = parsed['tool']['dephell']['example']
    assert parsed['from']['format'] == 'pip'
    assert parsed['from']['path'] == 'requirements.in'
    assert parsed['to']['format'] == 'piplock'
    assert parsed['to']['path'] == 'requirements.lock' 
开发者ID:dephell,项目名称:dephell,代码行数:22,代码来源:test_generate_config.py


注:本文中的tomlkit.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。