def _capture_environment(environment, gist_slug, version): """Capture the python environment and attach it to the commit""" if environment is not None: # Check credentials if environment config exists creds = read_creds() if 'DEFAULT_CONFIG' in creds and 'environment' in creds['DEFAULT_CONFIG']: environment_config = creds['DEFAULT_CONFIG']['environment'] if not environment_config: # Disable environment capture return if environment == 'auto' and (environment_config == 'conda' or environment_config == 'pip'): environment = environment_config log('Capturing environment..') captured = False if environment == 'auto' or environment == 'conda': # Capture conda environment try: upload_conda_env(gist_slug, version) captured = True except CondaError as e: log(str(e), error=True) if not captured and (environment == 'pip' or environment == 'auto'): # Capture pip environment try: upload_pip_env(gist_slug, version) except Exception as e: log(str(e), error=True)
def test_upload_pip_env(mock_popen, mock_upload_file): mock_popen().read.return_value = pip_env upload_pip_env('fake_gist_slug', version=2) mock_upload_file.assert_called_with(gist_slug='fake_gist_slug', file=('requirements.txt', pip_env), version=2)