def test_unsetting_entire_section(project_dir, write_project_file):
    ini_contents = "\n".join(("[populus]", "", "[extra_section]")).format(project_dir=project_dir)
    write_project_file("populus.ini", ini_contents)

    populus_ini_path = os.path.join(project_dir, "populus.ini")

    config = load_config([populus_ini_path])
    assert config.has_section("extra_section")

    runner = CliRunner()
    result = runner.invoke(main, ["config:unset", "--section", "extra_section", "--no-confirm", "*"])

    assert result.exit_code == 0, result.output + str(result.exception)

    config = load_config([populus_ini_path])
    assert not config.has_section("extra_section")
def test_setting_overwritting_value(project_dir, write_project_file):
    ini_contents = "\n".join(("[populus]", "default_chain=mainnet")).format(project_dir=project_dir)
    write_project_file("populus.ini", ini_contents)

    populus_ini_path = os.path.join(project_dir, "populus.ini")

    config = load_config([populus_ini_path])
    assert config.get("populus", "default_chain") == "mainnet"

    runner = CliRunner()
    result = runner.invoke(main, ["config:set", "default_chain:testnet"])

    assert result.exit_code == 0, result.output + str(result.exception)

    config = load_config([populus_ini_path])
    assert config.get("populus", "default_chain") == "testnet"
def test_unsetting_value_that_is_not_present(project_dir, write_project_file):
    ini_contents = '\n'.join(("[populus]", )).format(project_dir=project_dir)
    write_project_file('populus.ini', ini_contents)

    populus_ini_path = os.path.join(project_dir, 'populus.ini')

    config = load_config([populus_ini_path])
    assert not config.has_option('populus', 'default_chain')

    runner = CliRunner()
    result = runner.invoke(main, ['config:unset', 'default_chain'])

    assert result.exit_code == 0, result.output + str(result.exception)

    config = load_config([populus_ini_path])
    assert not config.has_option('populus', 'default_chain')
def test_unsetting_value_that_is_not_present(project_dir, write_project_file):
    ini_contents = "\n".join(("[populus]",)).format(project_dir=project_dir)
    write_project_file("populus.ini", ini_contents)

    populus_ini_path = os.path.join(project_dir, "populus.ini")

    config = load_config([populus_ini_path])
    assert not config.has_option("populus", "default_chain")

    runner = CliRunner()
    result = runner.invoke(main, ["config:unset", "default_chain"])

    assert result.exit_code == 0, result.output + str(result.exception)

    config = load_config([populus_ini_path])
    assert not config.has_option("populus", "default_chain")
def test_chains_property(project_dir, write_project_file):
    ini_contents = "\n".join(
        ("[populus]", "project_dir={project_dir}", "", "[chain:local]", "provider=web3.providers.ipc.IPCProvider")
    ).format(project_dir=project_dir)
    write_project_file("populus.ini", ini_contents)

    config = load_config(get_config_paths(project_dir, []))

    assert "local" in config.chains
def test_custom_declared_chain_configuration(project_dir, write_project_file):
    ini_contents = "\n".join(
        ("[populus]", "project_dir={project_dir}", "", "[chain:mainnet]", "provider=web3.providers.rpc.RPCProvider")
    ).format(project_dir=project_dir)
    write_project_file("populus.ini", ini_contents)

    config = load_config(get_config_paths(project_dir, []))

    assert config.chains["mainnet"]["provider"] == "web3.providers.rpc.RPCProvider"
def test_is_external_converts_to_boolean(project_dir, write_project_file):
    ini_contents = '\n'.join((
        "[chain:parity]",
        "is_external=true",
    )).format(project_dir=project_dir)
    write_project_file('populus.ini', ini_contents)

    config = load_config(get_config_paths(project_dir, []))

    assert config.chains['parity']['is_external'] is True
def test_setting_overwritting_value(project_dir, write_project_file):
    ini_contents = '\n'.join((
        "[populus]",
        "default_chain=mainnet",
    )).format(project_dir=project_dir)
    write_project_file('populus.ini', ini_contents)

    populus_ini_path = os.path.join(project_dir, 'populus.ini')

    config = load_config([populus_ini_path])
    assert config.get('populus', 'default_chain') == 'mainnet'

    runner = CliRunner()
    result = runner.invoke(main, ['config:set', 'default_chain:testnet'])

    assert result.exit_code == 0, result.output + str(result.exception)

    config = load_config([populus_ini_path])
    assert config.get('populus', 'default_chain') == 'testnet'
Example #9
0
def test_loading_single_config_file(project_dir, write_project_file):
    ini_contents = '\n'.join((
        "[populus]",
        "project_dir={project_dir}",
    )).format(project_dir=project_dir)
    write_project_file('populus.ini', ini_contents)

    config = load_config(get_config_paths(project_dir, []))

    assert config.get('populus', 'project_dir') == project_dir
def test_loading_single_config_file(project_dir, write_project_file):
    ini_contents = '\n'.join((
        "[populus]",
        "project_dir={project_dir}",
    )).format(project_dir=project_dir)
    write_project_file('populus.ini', ini_contents)

    config = load_config(get_config_paths(project_dir, []))

    assert config.get('populus', 'project_dir') == project_dir
def test_setting_non_default_section(project_dir, write_project_file):
    ini_contents = "\n".join(("[populus]",)).format(project_dir=project_dir)
    write_project_file("populus.ini", ini_contents)

    populus_ini_path = os.path.join(project_dir, "populus.ini")

    config = load_config([populus_ini_path])
    assert not config.has_section("chain:mainnet")

    runner = CliRunner()
    result = runner.invoke(
        main, ["config:set", "--section", "chain:mainnet", "provider:web3.providers.rpc.RPCProvider"]
    )

    assert result.exit_code == 0, result.output + str(result.exception)

    config = load_config([populus_ini_path])
    assert config.has_section("chain:mainnet")
    assert config.chains["mainnet"]["provider"] == "web3.providers.rpc.RPCProvider"
Example #12
0
    def load_config(self, config_file_paths=None):
        self._config_file_paths = config_file_paths

        if not config_file_paths:
            config_file_paths = get_config_paths(os.getcwd())
        else:
            self.primary_config_file_path = config_file_paths[0]

        if is_string(config_file_paths):
            config_file_paths = [config_file_paths]

        self.config = load_config(config_file_paths)
def test_setting_non_default_section(project_dir, write_project_file):
    ini_contents = '\n'.join(("[populus]", )).format(project_dir=project_dir)
    write_project_file('populus.ini', ini_contents)

    populus_ini_path = os.path.join(project_dir, 'populus.ini')

    config = load_config([populus_ini_path])
    assert not config.has_section('chain:mainnet')

    runner = CliRunner()
    result = runner.invoke(main, [
        'config:set', '--section', 'chain:mainnet',
        'provider:web3.providers.rpc.RPCProvider'
    ])

    assert result.exit_code == 0, result.output + str(result.exception)

    config = load_config([populus_ini_path])
    assert config.has_section('chain:mainnet')
    assert config.chains['mainnet'][
        'provider'] == 'web3.providers.rpc.RPCProvider'
def test_chains_property(project_dir, write_project_file):
    ini_contents = '\n'.join((
        "[populus]",
        "project_dir={project_dir}",
        "",
        "[chain:local]",
        "provider=web3.providers.ipc.IPCProvider",
    )).format(project_dir=project_dir)
    write_project_file('populus.ini', ini_contents)

    config = load_config(get_config_paths(project_dir, []))

    assert 'local' in config.chains
def test_unsetting_entire_section(project_dir, write_project_file):
    ini_contents = '\n'.join((
        "[populus]",
        "",
        "[extra_section]",
    )).format(project_dir=project_dir)
    write_project_file('populus.ini', ini_contents)

    populus_ini_path = os.path.join(project_dir, 'populus.ini')

    config = load_config([populus_ini_path])
    assert config.has_section('extra_section')

    runner = CliRunner()
    result = runner.invoke(
        main,
        ['config:unset', '--section', 'extra_section', '--no-confirm', '*'])

    assert result.exit_code == 0, result.output + str(result.exception)

    config = load_config([populus_ini_path])
    assert not config.has_section('extra_section')
def test_setting_with_no_config_file_lazily_creates_file(project_dir):
    populus_ini_path = os.path.join(project_dir, 'populus.ini')

    assert not os.path.exists(populus_ini_path)

    runner = CliRunner()
    result = runner.invoke(main, ['config:set', 'default_chain:testnet'])

    assert result.exit_code == 0, result.output + str(result.exception)

    assert os.path.exists(populus_ini_path)

    config = load_config([populus_ini_path])
    assert config.get('populus', 'default_chain') == 'testnet'
def test_setting_with_no_config_file_lazily_creates_file(project_dir):
    populus_ini_path = os.path.join(project_dir, "populus.ini")

    assert not os.path.exists(populus_ini_path)

    runner = CliRunner()
    result = runner.invoke(main, ["config:set", "default_chain:testnet"])

    assert result.exit_code == 0, result.output + str(result.exception)

    assert os.path.exists(populus_ini_path)

    config = load_config([populus_ini_path])
    assert config.get("populus", "default_chain") == "testnet"
def test_custom_declared_chain_configuration(project_dir, write_project_file):
    ini_contents = '\n'.join((
        "[populus]",
        "project_dir={project_dir}",
        "",
        "[chain:mainnet]",
        "provider=web3.providers.rpc.RPCProvider",
    )).format(project_dir=project_dir)
    write_project_file('populus.ini', ini_contents)

    config = load_config(get_config_paths(project_dir, []))

    assert config.chains['mainnet'][
        'provider'] == 'web3.providers.rpc.RPCProvider'
def test_loading_multiple_config_files(project_dir, write_project_file):
    primary_ini_contents = '\n'.join((
        "[populus]",
        "project_dir={project_dir}",
    )).format(project_dir=project_dir)

    write_project_file('populus.ini', primary_ini_contents)

    other_ini_contents = '\n'.join((
        "[populus]",
        "project_dir=/should-not-override/",
    )).format(project_dir=project_dir)

    write_project_file('./subdir/populus.ini', other_ini_contents)


    config = load_config(get_config_paths(
        project_dir,
        [os.path.join(project_dir, 'subdir')],
    ))

    assert config.get('populus', 'project_dir') == project_dir
Example #20
0
def test_loading_multiple_config_files(project_dir, write_project_file):
    primary_ini_contents = '\n'.join((
        "[populus]",
        "project_dir={project_dir}",
    )).format(project_dir=project_dir)

    write_project_file('populus.ini', primary_ini_contents)

    other_ini_contents = '\n'.join((
        "[populus]",
        "project_dir=/should-not-override/",
    )).format(project_dir=project_dir)

    write_project_file('./subdir/populus.ini', other_ini_contents)

    config = load_config(
        get_config_paths(
            project_dir,
            [os.path.join(project_dir, 'subdir')],
        ))

    assert config.get('populus', 'project_dir') == project_dir
def test_testing_chain_config_defaults(project_dir):
    config = load_config(get_config_paths(project_dir, []))

    assert 'testrpc' in config.chains
def test_mainnet_chain_config_defaults(project_dir):
    config = load_config(get_config_paths(project_dir, []))

    assert 'mainnet' in config.chains
def test_testing_chain_config_defaults(project_dir):
    config = load_config(get_config_paths(project_dir, []))

    assert "testrpc" in config.chains
def test_mainnet_chain_config_defaults(project_dir):
    config = load_config(get_config_paths(project_dir, []))

    assert "mainnet" in config.chains