def test_initializing_with_legacy_ini_config(project_dir, write_project_file): default_contracts_dir = get_contracts_source_dir(project_dir) os.rmdir(default_contracts_dir) write_project_file('populus.ini', "[populus]\ncontracts_dir=./custom-contracts-dir") contracts_source_dir = os.path.join(project_dir, 'custom-contracts-dir') expected_paths = ( os.path.join(project_dir, 'populus.json'), contracts_source_dir, os.path.join(contracts_source_dir, 'Greeter.sol'), os.path.join(project_dir, 'tests'), os.path.join(project_dir, 'tests', 'test_greeter.py'), ) for path in expected_paths: assert not os.path.exists(path) runner = CliRunner() result = runner.invoke(main, ['init'], input='\n') assert result.exit_code == 0, result.output + str(result.exception) for path in expected_paths: assert os.path.exists(path), result.output
def _loaded_contract_fixtures(populus_source_root, 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_fn, contracts_to_load_from_module, ) contracts_source_dir = get_contracts_source_dir(project_dir) for item 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)) dst_path = os.path.join(contracts_source_dir, os.path.basename(item)) if os.path.exists(dst_path): raise ValueError("File already present at '{0}'".format(dst_path)) shutil.copy(src_path, dst_path)
def project_dir(tmpdir, monkeypatch): _project_dir = str(tmpdir.mkdir("project-dir")) # setup project directories ensure_path_exists(get_contracts_source_dir(_project_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() contracts_source_dir = get_contracts_source_dir(project_dir) assert is_same_path(project.contracts_source_dir, contracts_source_dir) 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() contracts_source_dir = get_contracts_source_dir(project_dir) assert is_same_path(project.contracts_source_dir, contracts_source_dir) with pytest.warns(DeprecationWarning): assert is_same_path(project.contracts_dir, contracts_source_dir) build_asset_dir = get_build_asset_dir(project_dir) assert is_same_path(project.build_asset_dir, build_asset_dir) with pytest.warns(DeprecationWarning): assert is_same_path(project.build_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) with pytest.warns(DeprecationWarning): assert is_same_path(project.compiled_contracts_file_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) with pytest.warns(DeprecationWarning): assert is_same_path(project.blockchains_dir, base_blockchain_storage_dir) data_dir = get_data_dir(project_dir, 'some-test-chain-name') with pytest.warns(DeprecationWarning): assert is_same_path( project.get_blockchain_data_dir('some-test-chain-name'), data_dir) chaindata_dir = get_chaindata_dir(data_dir) with pytest.warns(DeprecationWarning): assert is_same_path( project.get_blockchain_chaindata_dir('some-test-chain-name'), chaindata_dir) geth_ipc_path = get_geth_ipc_path(data_dir) with pytest.warns(DeprecationWarning): assert is_same_path( project.get_blockchain_ipc_path('some-test-chain-name'), geth_ipc_path)
def test_initializing_empty_project(project_dir): contracts_source_dir = get_contracts_source_dir(project_dir) os.rmdir(contracts_source_dir) expected_paths = ( os.path.join(project_dir, 'populus.json'), contracts_source_dir, os.path.join(contracts_source_dir, 'Greeter.sol'), os.path.join(project_dir, 'tests'), os.path.join(project_dir, 'tests', 'test_greeter.py'), ) for path in expected_paths: assert not os.path.exists(path) 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 contracts_source_dir(self): return self.config.get( 'compilation.contracts_source_dir', get_contracts_source_dir(self.project_dir), )
def contracts_source_dir(self): if 'compilation.contracts_dir' in self.config: return self.config['compilation.contracts_dir'] else: return get_contracts_source_dir(self.project_dir)