Exemple #1
0
def test_initializing_empty_project(project_dir):
    contracts_source_dirs = get_contracts_source_dirs(project_dir)

    for source_dir in contracts_source_dirs:
        os.rmdir(source_dir)

    expected_paths = (
        os.path.join(project_dir, 'tests'),
        os.path.join(contracts_source_dirs[0], 'Greeter.sol'),
        os.path.join(project_dir, 'tests', 'test_greeter.py'),
    ) + tuple(source_dir for source_dir in contracts_source_dirs)

    for path in expected_paths:
        assert not os.path.exists(path)

    assert not os.path.exists(os.path.join(project_dir, 'project.json'))

    runner = CliRunner()
    result = runner.invoke(main, ['init'])

    assert result.exit_code == 0, result.output + str(result.exception)
    assert 'Created Example Contract' in result.output

    for path in expected_paths:
        assert os.path.exists(path)
def test_initializing_empty_project(project_dir):
    contracts_source_dirs = get_contracts_source_dirs(project_dir)

    for source_dir in contracts_source_dirs:
        os.rmdir(source_dir)

    expected_paths = (
        os.path.join(project_dir, 'tests'),
        os.path.join(contracts_source_dirs[0], 'Greeter.sol'),
        os.path.join(project_dir, 'tests', 'test_greeter.py'),
    ) + tuple(
        source_dir for source_dir in contracts_source_dirs
    )

    for path in expected_paths:
        assert not os.path.exists(path)

    assert not os.path.exists(os.path.join(project_dir, 'project.json'))

    runner = CliRunner()
    result = runner.invoke(main, ['init'])

    assert result.exit_code == 0, result.output + str(result.exception)
    assert 'Created Example Contract' in result.output

    for path in expected_paths:
        assert os.path.exists(path)
Exemple #3
0
 def contracts_source_dirs(self):
     source_dirs = self.config.get('compilation.contracts_source_dirs')
     if source_dirs:
         return [
             os.path.join(self.project_dir, contracts_dir)
             for contracts_dir in source_dirs
         ]
     else:
         return get_contracts_source_dirs(self.project_dir)
Exemple #4
0
 def contracts_source_dir(self):
     warnings.warn(
         DeprecationWarning(
             "project.contracts_source_dir has been replaced by the plural, "
             "project.contracts_source_dirs which is an iterable of all source "
             "directories populus will search for contracts.  Please update your "
             "code accordingly as this API will be removed in a future release"
         ))
     return self.config.get(
         'compilation.contracts_source_dir',
         get_contracts_source_dirs(self.project_dir),
     )[0]
Exemple #5
0
def project_dir(tmpdir, monkeypatch):
    _project_dir = str(tmpdir.mkdir("project-dir"))

    # setup project directories
    for source_dir in get_contracts_source_dirs(_project_dir):
        ensure_path_exists(source_dir)
    ensure_path_exists(get_build_asset_dir(_project_dir))
    ensure_path_exists(get_base_blockchain_storage_dir(_project_dir))

    monkeypatch.chdir(_project_dir)
    monkeypatch.syspath_prepend(_project_dir)

    return _project_dir
Exemple #6
0
def project_dir(tmpdir, monkeypatch):
    _project_dir = str(tmpdir.mkdir("project-dir"))

    # setup project directories
    for source_dir in get_contracts_source_dirs(_project_dir):
        ensure_path_exists(source_dir)
    ensure_path_exists(get_build_asset_dir(_project_dir))
    ensure_path_exists(get_base_blockchain_storage_dir(_project_dir))

    monkeypatch.chdir(_project_dir)
    monkeypatch.syspath_prepend(_project_dir)

    return _project_dir
def test_project_directory_properties(project_dir):
    project = Project(project_dir)

    contracts_source_dirs = get_contracts_source_dirs(project_dir)
    for left, right in zip(project.contracts_source_dirs, contracts_source_dirs):
        assert is_same_path(left, right)

    build_asset_dir = get_build_asset_dir(project_dir)
    assert is_same_path(project.build_asset_dir, build_asset_dir)

    compiled_contracts_asset_path = get_compiled_contracts_asset_path(build_asset_dir)
    assert is_same_path(project.compiled_contracts_asset_path, compiled_contracts_asset_path)

    base_blockchain_storage_dir = get_base_blockchain_storage_dir(project_dir)
    assert is_same_path(project.base_blockchain_storage_dir, base_blockchain_storage_dir)
def test_project_directory_properties(project_dir):
    project = Project(project_dir, create_config_file=True)

    contracts_source_dirs = get_contracts_source_dirs(project_dir)
    for left, right in zip(project.contracts_source_dirs, contracts_source_dirs):
        assert is_same_path(left, right)

    build_asset_dir = get_build_asset_dir(project_dir)
    assert is_same_path(project.build_asset_dir, build_asset_dir)

    compiled_contracts_asset_path = get_compiled_contracts_asset_path(build_asset_dir)
    assert is_same_path(project.compiled_contracts_asset_path, compiled_contracts_asset_path)

    base_blockchain_storage_dir = get_base_blockchain_storage_dir(project_dir)
    assert is_same_path(project.base_blockchain_storage_dir, base_blockchain_storage_dir)
Exemple #9
0
def _loaded_contract_fixtures(project_dir, request):
    contracts_to_load_from_fn = getattr(request.function,
                                        '_populus_contract_fixtures', [])
    contracts_to_load_from_module = getattr(request.module,
                                            '_populus_contract_fixtures', [])

    contracts_to_load = itertools.chain(
        contracts_to_load_from_module,
        contracts_to_load_from_fn,
    )
    contracts_source_dir = get_contracts_source_dirs(project_dir)[0]

    for item, dst_path in contracts_to_load:
        ensure_path_exists(contracts_source_dir)

        fixture_path = os.path.join(
            POPULUS_SOURCE_ROOT,
            'tests',
            'fixtures',
            item,
        )

        if os.path.exists(item):
            src_path = item
        elif os.path.exists(fixture_path):
            src_path = fixture_path
        else:
            raise ValueError("Unable to load contract '{0}'".format(item))

        if dst_path is None:
            dst_path = os.path.join(contracts_source_dir,
                                    os.path.basename(item))
        elif not os.path.isabs(dst_path):
            dst_path = os.path.join(project_dir, dst_path)

        ensure_path_exists(os.path.dirname(dst_path))

        if os.path.exists(dst_path):
            raise ValueError("File already present at '{0}'".format(dst_path))

        shutil.copy(src_path, dst_path)
Exemple #10
0
def _loaded_contract_fixtures(project_dir, request):
    contracts_to_load_from_fn = getattr(request.function, '_populus_contract_fixtures', [])
    contracts_to_load_from_module = getattr(request.module, '_populus_contract_fixtures', [])

    contracts_to_load = itertools.chain(
        contracts_to_load_from_module,
        contracts_to_load_from_fn,
    )
    contracts_source_dir = get_contracts_source_dirs(project_dir)[0]

    for item, dst_path in contracts_to_load:
        ensure_path_exists(contracts_source_dir)

        fixture_path = os.path.join(
            POPULUS_SOURCE_ROOT,
            'tests',
            'fixtures',
            item,
        )

        if os.path.exists(item):
            src_path = item
        elif os.path.exists(fixture_path):
            src_path = fixture_path
        else:
            raise ValueError("Unable to load contract '{0}'".format(item))

        if dst_path is None:
            dst_path = os.path.join(contracts_source_dir, os.path.basename(item))
        elif not os.path.isabs(dst_path):
            dst_path = os.path.join(project_dir, dst_path)

        ensure_path_exists(os.path.dirname(dst_path))

        if os.path.exists(dst_path):
            raise ValueError("File already present at '{0}'".format(dst_path))

        shutil.copy(src_path, dst_path)
def test_project_directory_properties(project_dir):
    project = Project(project_dir, create_config_file=True)

    if sys.version_info.major != 2:
        with pytest.warns(DeprecationWarning):
            project.contracts_source_dir

    contracts_source_dirs = get_contracts_source_dirs(project_dir)
    for left, right in zip(project.contracts_source_dirs,
                           contracts_source_dirs):
        assert is_same_path(left, right)

    build_asset_dir = get_build_asset_dir(project_dir)
    assert is_same_path(project.build_asset_dir, build_asset_dir)

    compiled_contracts_asset_path = get_compiled_contracts_asset_path(
        build_asset_dir)
    assert is_same_path(project.compiled_contracts_asset_path,
                        compiled_contracts_asset_path)

    base_blockchain_storage_dir = get_base_blockchain_storage_dir(project_dir)
    assert is_same_path(project.base_blockchain_storage_dir,
                        base_blockchain_storage_dir)
Exemple #12
0
 def contracts_source_dirs(self):
     source_dirs = self.config.get('compilation.contracts_source_dirs')
     if source_dirs:
         return [os.path.join(self.project_dir, contracts_dir) for contracts_dir in source_dirs]
     else:
         return get_contracts_source_dirs(self.project_dir)