def test_extract_pip_packages(self): dep = extract_pip_packages(env_fname='environment-test.yml') dep2 = extract_pip_packages(env_fname='empty-yaml-file.yml') self.assertListEqual(dep, ['six==1.11.0', 'sqlite==2.0.0']) self.assertListEqual(dep2, []) with self.assertRaises(FileNotFoundError): extract_env_packages(env_fname='non-existent-file.yml')
def install(env_fname=None, env_name=None): """Install packages for a cloned gist""" # Check for conda and get the binary path conda_bin = get_conda_bin() # Identify the right environment file, and exit if absent env_fname = identify_env_file(env_fname=env_fname) if env_fname is None: log('Failed to detect a conda environment YML file. Skipping..', error=True) return else: log('Detected conda environment file: ' + env_fname + "\n") # Get the environment name from user input env_name = request_env_name(env_name=env_name, env_fname=env_fname) if env_name is None: log('Environment name not provided/detected. Skipping..') return # Construct the command command = conda_bin + ' env update --file "' + \ env_fname + '" --name "' + env_name + '"' packages = extract_env_packages(env_fname=env_fname) if len(packages) > 0: success = run_command(command=command, env_fname=env_fname, packages=packages, run=1) if not success: print('Some pip packages failed to install.') print_conda_message(env_name=env_name)
def test_remove_packages_pip(self): packages = extract_env_packages(env_fname='environment-test.yml') dependencies = ['dep1', 'mixpanel=1.11.0', {'pip': ['six==1.11.0', 'dep3']}] expected_result = ['dep1', {'pip': ['dep3']}] self.assertEqual(remove_packages(dependencies, packages), expected_result)
def test_remove_packages(self): packages = extract_env_packages(env_fname='environment-test.yml') dependencies = ['dep1', 'dep2', 'mixpanel=1.11.0', 'sqlite'] expected_result = ['dep1', 'dep2'] self.assertEqual(remove_packages(dependencies, packages), expected_result)
def test_extract_package_from_line(self): packages = extract_env_packages(env_fname='environment-test.yml') lines = [['- mixpanel=1.11.0', 'mixpanel=1.11.0'], ['sqlite<3x not compatible', 'sqlite'], ['', None], ['line containing six < 3.0.x', 'six==1.11.0']] for line in lines: self.assertEqual(extract_package_from_line(line=line[0], packages=packages), line[1])
def test_check_error(self): packages = extract_env_packages(env_fname='environment-test.yml') error_str = '''ResolvePackageNotFound: - mixpanel=1.11.0''' error_str2 = '''UnsatisfiableError: - sigmasix=1.91.0''' error_str3 = '''AnyOtherException: - sigmasix=1.91.0''' error, pkgs = check_error(error_str=error_str, packages=packages) error2, pkgs2 = check_error(error_str=error_str2, packages=packages) error3, pkgs3 = check_error(error_str=error_str3, packages=packages) self.assertEqual(error, 'unresolved') self.assertListEqual(pkgs, ['mixpanel=1.11.0']) self.assertEqual(error2, 'unsatisfiable') self.assertListEqual(pkgs2, ['sigmasix=1.91.0']) self.assertIsNone(error3) self.assertListEqual(pkgs3, [])
def test_remove_packages(dependencies, expected_result): with fake_envfile(): packages = extract_env_packages(env_fname='environment.yml') assert remove_packages(dependencies, packages) == expected_result
def test_extract_package_from_line(line, expected_result): with fake_envfile(): packages = extract_env_packages(env_fname='environment.yml') assert extract_package_from_line(line=line, packages=packages) == expected_result
def test_check_error(error_str, expected_result): with fake_envfile(): packages = extract_env_packages(env_fname='environment.yml') assert check_error(error_str=error_str, packages=packages) == expected_result