def test_robustus(tmpdir): tmpdir.chdir() test_env = 'test_env' # create env and install some packages logging.info('creating ' + test_env) robustus.execute(['env', test_env]) assert os.path.isdir(test_env) assert os.path.isfile(os.path.join(test_env, '.robustus')) robustus_executable = os.path.join(test_env, 'bin/robustus') assert os.path.isfile(robustus_executable) # install some packages logging.info('installing requirements into ' + test_env) run_shell([robustus_executable, 'install', 'pyserial']) test_requirements1 = 'test_requirements1.txt' with open(test_requirements1, 'w') as file: file.write('pep8==1.3.3\n') file.write('pytest==2.3.5\n') run_shell([robustus_executable, 'install', '-r', test_requirements1]) # check packages are installed packages_to_check = ['pyserial', 'pep8==1.3.3', 'pytest==2.3.5'] with open('freezed_requirements.txt', 'w') as req_file: run_shell([robustus_executable, 'freeze'], stdout=req_file) with open('freezed_requirements.txt') as req_file: installed_packages = [line.strip() for line in req_file] for package in packages_to_check: assert package in installed_packages assert check_module_available(test_env, 'serial') assert check_module_available(test_env, 'pep8') assert check_module_available(test_env, 'pytest') shutil.rmtree(test_env)
def test_install_with_branch_testing(tmpdir): """Create a package with some editable requirements and install using a branch and check that one repo with the branch gets checked out using the branch and the other ends up on master (this is how testing is often done).""" base_dir = str(tmpdir.mkdir('test_perrepo_env')) test_env = os.path.join(base_dir, 'env') working_dir = os.path.join(base_dir, 'working_dir') # create env and install some packages logging.info('creating ' + test_env) os.mkdir(working_dir) os.chdir(working_dir) os.system('git init .') robustus.execute(['env', test_env]) os.chdir(working_dir) robustus_executable = os.path.join(test_env, 'bin/robustus') test_requirements = os.path.join(working_dir, 'requirements.txt') with open(test_requirements, 'w') as file: file.write('-e git+https://github.com/braincorp/robustus-test-repo.git@master#egg=ardrone\nmock==0.8.0\nopencv==2.4.8\n-e git+https://github.com/braincorp/filecacher.git@master#egg=filecacher\n') run_shell([robustus_executable, 'install', '--tag', 'test-branch', '-r', test_requirements, '--ignore-missing-refs'], verbose = True) # Now check that robustus behaves as expected assert os.path.exists(os.path.join(test_env, 'src', 'ardrone', 'test_branch.file')) assert os.path.exists(os.path.join(test_env, 'lib', 'python2.7', 'site-packages', 'python-ardrone.egg-link')) assert os.path.exists(os.path.join(test_env, 'src', 'filecacher', 'requirements.txt')) assert os.path.exists(os.path.join(test_env, 'lib', 'python2.7', 'site-packages', 'filecacher.egg-link'))
def test_install_with_tag(tmpdir): """Create a package with some editable requirements and install using a tag.""" base_dir = str(tmpdir.mkdir('test_perrepo_env')) test_env = os.path.join(base_dir, 'env') working_dir = os.path.join(base_dir, 'working_dir') # create env and install some packages logging.info('creating ' + test_env) os.mkdir(working_dir) os.chdir(working_dir) os.system('git init .') robustus.execute(['env', test_env]) os.chdir(working_dir) robustus_executable = os.path.join(test_env, 'bin/robustus') test_requirements = os.path.join(working_dir, 'requirements.txt') with open(test_requirements, 'w') as file: file.write( '-e git+https://github.com/braincorp/robustus-test-repo.git@master#egg=robustus-test-repo\n' ) run_shell([ robustus_executable, 'install', '--tag', 'test-tag', '-r', test_requirements ]) # Now check that robustus behaves as expected assert os.path.exists( os.path.join(test_env, 'src', 'robustus-test-repo', 'test-tag'))
def perform_standard_test(package, python_imports=[], package_files=[], dependencies=[], postinstall_script=None, test_env='test_env', test_cache='test_wheelhouse', options=[], install_options=[]): """ create env, install package, check package is available, remove env, install package without index, check package is available :return: None """ logging.basicConfig(format="%(message)s", level=logging.INFO) # create env and install bullet into it test_env = os.path.abspath(test_env) test_cache = os.path.abspath(test_cache) robustus.execute(options + ['--debug', '--cache', test_cache, 'env', test_env]) install_dependencies(test_env, dependencies, options) robustus.execute(options + ['--debug', '--env', test_env, 'install', package] + install_options) check_module(test_env, python_imports, package_files, postinstall_script) shutil.rmtree(test_env) # install again, but using only cache robustus.execute(options + ['--debug', '--cache', test_cache, 'env', test_env]) install_dependencies(test_env, dependencies, options) robustus.execute(options + ['--debug', '--env', test_env, 'install', package, '--no-index'] + install_options) check_module(test_env, python_imports, package_files, postinstall_script) shutil.rmtree(test_env) shutil.rmtree(test_cache)
def create_editable_environment(tmpdir): """Create an environment with an editable (shared between some tests) and chdir into it.""" base_dir = str(tmpdir.mkdir('test_perrepo_env')) test_env = os.path.join(base_dir, 'env') working_dir = os.path.join(base_dir, 'working_dir') # create env and install some packages logging.info('creating ' + test_env) os.mkdir(working_dir) os.chdir(working_dir) os.system('git init .') robustus.execute(['env', test_env]) os.chdir(working_dir) robustus_executable = os.path.join(test_env, 'bin/robustus') test_requirements = os.path.join(working_dir, 'requirements.txt') with open(test_requirements, 'w') as file: file.write('-e git+https://github.com/braincorp/robustus-test-repo.git@master#egg=ardrone\n') run_shell([robustus_executable, 'install', '-r', test_requirements]) return working_dir, test_env, robustus_executable
def test_install_with_tag(tmpdir): """Create a package with some editable requirements and install using a tag.""" base_dir = str(tmpdir.mkdir('test_perrepo_env')) test_env = os.path.join(base_dir, 'env') working_dir = os.path.join(base_dir, 'working_dir') # create env and install some packages logging.info('creating ' + test_env) os.mkdir(working_dir) os.chdir(working_dir) os.system('git init .') robustus.execute(['env', test_env]) os.chdir(working_dir) robustus_executable = os.path.join(test_env, 'bin/robustus') test_requirements = os.path.join(working_dir, 'requirements.txt') with open(test_requirements, 'w') as file: file.write('-e git+https://github.com/braincorp/robustus-test-repo.git@master#egg=robustus-test-repo\n') run_shell([robustus_executable, 'install', '--tag', 'test-tag', '-r', test_requirements]) # Now check that robustus behaves as expected assert os.path.exists(os.path.join(test_env, 'src', 'robustus-test-repo', 'test-tag'))
def create_editable_environment(tmpdir): """Create an environment with an editable (shared between some tests) and chdir into it.""" base_dir = str(tmpdir.mkdir('test_perrepo_env')) test_env = os.path.join(base_dir, 'env') working_dir = os.path.join(base_dir, 'working_dir') # create env and install some packages logging.info('creating ' + test_env) os.mkdir(working_dir) os.chdir(working_dir) os.system('git init .') robustus.execute(['env', test_env]) os.chdir(working_dir) robustus_executable = os.path.join(test_env, 'bin/robustus') test_requirements = os.path.join(working_dir, 'requirements.txt') with open(test_requirements, 'w') as file: file.write( '-e git+https://github.com/braincorp/robustus-test-repo.git@master#egg=ardrone\n' ) run_shell([robustus_executable, 'install', '-r', test_requirements]) return working_dir, test_env, robustus_executable
def install_dependencies(test_env, dependencies, options): for dep in dependencies: robustus.execute(options + ['--env', test_env, 'install', dep])
def install_dependencies(test_env, dependencies, options): for dep in dependencies: robustus.execute(options + ["--env", test_env, "install", dep])
def test_install_with_branch_testing(tmpdir): """Create a package with some editable requirements and install using a branch and check that one repo with the branch gets checked out using the branch and the other ends up on master (this is how testing is often done).""" base_dir = str(tmpdir.mkdir('test_perrepo_env')) test_env = os.path.join(base_dir, 'env') working_dir = os.path.join(base_dir, 'working_dir') # create env and install some packages logging.info('creating ' + test_env) os.mkdir(working_dir) os.chdir(working_dir) # creat a new local repo os.system('git init .') setup_file_content =\ ''' from setuptools import setup, find_packages setup( name='test_perrepo_env', author='Brain Corporation', author_email='*****@*****.**', url='https://github.com/braincorp/test_perrepo_env', long_description='', version='dev', packages=find_packages(), include_package_data=True, install_requires=[]) ''' setup_file = os.path.join(working_dir, 'setup.py') with open(setup_file, 'w') as file: file.write(setup_file_content) test_requirements = os.path.join(working_dir, 'requirements.txt') with open(test_requirements, 'w') as file: file.write('-e git+https://github.com/braincorp/robustus-test-repo.git@master#egg=robustus-test-repo\nmock==0.8.0\n-e git+https://github.com/braincorp/filecacher.git@master#egg=filecacher\n') os.system('git add setup.py') os.system('git add requirements.txt') os.system('git commit -am "setup and reqs"') # create test branch os.system('git checkout -b test-branch') test_file_on_test_branch = os.path.join(working_dir, 'root_test_branch.file') with open(test_file_on_test_branch, 'w') as file: file.write('root test') os.system('git add root_test_branch.file') os.system('git commit -am "root_test_branch.file"') os.system('git checkout master') robustus.execute(['env', test_env]) os.chdir(working_dir) robustus_executable = os.path.join(test_env, 'bin/robustus') run_shell([robustus_executable, 'install', '-e', '.', '--tag', 'test-branch', '--ignore-missing-refs'], verbose = True) # Now check that robustus behaves as expected assert os.path.exists(os.path.join(test_env, 'src', 'robustus-test-repo', 'test_branch.file')) assert os.path.exists(os.path.join(test_env, 'lib', 'python2.7', 'site-packages', 'python-ardrone.egg-link')) assert os.path.exists(os.path.join(test_env, 'src', 'filecacher', 'requirements.txt')) assert os.path.exists(os.path.join(test_env, 'lib', 'python2.7', 'site-packages', 'filecacher.egg-link')) # Now check that the repo itself is on the test branch assert os.path.exists(test_file_on_test_branch)
def test_install_with_branch_testing(tmpdir): """Create a package with some editable requirements and install using a branch and check that one repo with the branch gets checked out using the branch and the other ends up on master (this is how testing is often done).""" base_dir = str(tmpdir.mkdir('test_perrepo_env')) test_env = os.path.join(base_dir, 'env') working_dir = os.path.join(base_dir, 'working_dir') # create env and install some packages logging.info('creating ' + test_env) os.mkdir(working_dir) os.chdir(working_dir) # creat a new local repo os.system('git init .') setup_file_content =\ ''' from setuptools import setup, find_packages setup( name='test_perrepo_env', author='Brain Corporation', author_email='*****@*****.**', url='https://github.com/braincorp/test_perrepo_env', long_description='', version='dev', packages=find_packages(), include_package_data=True, install_requires=[]) ''' setup_file = os.path.join(working_dir, 'setup.py') with open(setup_file, 'w') as file: file.write(setup_file_content) test_requirements = os.path.join(working_dir, 'requirements.txt') with open(test_requirements, 'w') as file: file.write( '-e git+https://github.com/braincorp/robustus-test-repo.git@master#egg=robustus-test-repo\nmock==0.8.0\n-e git+https://github.com/braincorp/filecacher.git@master#egg=filecacher\n' ) os.system('git add setup.py') os.system('git add requirements.txt') os.system('git commit -am "setup and reqs"') # create test branch os.system('git checkout -b test-branch') test_file_on_test_branch = os.path.join(working_dir, 'root_test_branch.file') with open(test_file_on_test_branch, 'w') as file: file.write('root test') os.system('git add root_test_branch.file') os.system('git commit -am "root_test_branch.file"') os.system('git checkout master') robustus.execute(['env', test_env]) os.chdir(working_dir) robustus_executable = os.path.join(test_env, 'bin/robustus') run_shell([ robustus_executable, 'install', '-e', '.', '--tag', 'test-branch', '--ignore-missing-refs' ], verbose=True) # Now check that robustus behaves as expected assert os.path.exists( os.path.join(test_env, 'src', 'robustus-test-repo', 'test_branch.file')) assert os.path.exists( os.path.join(test_env, 'lib', 'python2.7', 'site-packages', 'python-ardrone.egg-link')) assert os.path.exists( os.path.join(test_env, 'src', 'filecacher', 'requirements.txt')) assert os.path.exists( os.path.join(test_env, 'lib', 'python2.7', 'site-packages', 'filecacher.egg-link')) # Now check that the repo itself is on the test branch assert os.path.exists(test_file_on_test_branch)