def test_localized_config_interpreter_file(self): """ Test for interpreter file in a localized config. """ config_root = self._create_pipeline_configuration( "localized_core_with_interpreter" ) # Create interpreter file for good config. self._create_interpreter_file(config_root, sys.executable) # Create a localized config without an interpreter config_root_without_interpreter_file = self._create_pipeline_configuration( "localized_core_without_interpreter" ) # Create a localized config with a bad interpreter path config_root_with_bad_interpreter = self._create_pipeline_configuration( "localized_core_with_bad_interpreter" ) # Create interpreter file for config with bad interpreter location. self._create_interpreter_file(config_root_with_bad_interpreter, "/path/to/non/existing/python") # Test when the interpreter file is present and has a valid python interpreter. self.assertEqual( pipelineconfig_utils.get_python_interpreter_for_config(config_root), sys.executable ) # Test when the interpreter file is present but the interpreter path is bad. with self.assertRaises(TankInvalidInterpreterLocationError): pipelineconfig_utils.get_python_interpreter_for_config(config_root_with_bad_interpreter) # Test when the interpreter file is missing with self.assertRaisesRegexp(TankFileDoesNotExistError, "No interpreter file for"): pipelineconfig_utils.get_python_interpreter_for_config(config_root_without_interpreter_file)
def test_shared_config_interpreter_file(self): """ Test for interpreter file in a non-localized config. """ # Shared config with valid core. valid_studio_core = self._create_studio_core("valid_studio_core") self._create_interpreter_file(valid_studio_core, sys.executable) self.assertEqual( pipelineconfig_utils.get_python_interpreter_for_config( self._create_pipeline_configuration( "config_with_valid_studio_core", core_location=valid_studio_core)), sys.executable) # Test shared config with a bad interpreter location. studio_core_with_bad_interpreter_location = self._create_studio_core( "studio_core_with_bad_interpreter") self._create_interpreter_file( studio_core_with_bad_interpreter_location, "/path/to/missing/python") with self.assertRaises(TankInvalidInterpreterLocationError): pipelineconfig_utils.get_python_interpreter_for_config( self._create_pipeline_configuration( "config_using_studio_core_with_bad_interpreter", core_location=studio_core_with_bad_interpreter_location)) # Test shared config with missing interpreter file. studio_core_with_missing_interpreter_file_location = self._create_studio_core( "studio_core_with_missing_interpreter_file") with self.assertRaisesRegexp(TankFileDoesNotExistError, "No interpreter file for"): pipelineconfig_utils.get_python_interpreter_for_config( self._create_pipeline_configuration( "config_using_studio_core_with_missing_interpreter_file", core_location= studio_core_with_missing_interpreter_file_location)) # Test with a core location that is invalid. config_with_invalid_core_location = self._create_unlocalized_pipeline_configuration( "config_with_invalid_core") self._create_core_file(config_with_invalid_core_location, "/path/to/missing/core") with self.assertRaises(TankInvalidCoreLocationError): pipelineconfig_utils.get_python_interpreter_for_config( config_with_invalid_core_location) # Test when the core file is missing. config_with_no_core_file_location = self._create_unlocalized_pipeline_configuration( "config_with_no_core_file") with self.assertRaisesRegexp(TankFileDoesNotExistError, "is missing a core location file"): pipelineconfig_utils.get_python_interpreter_for_config( config_with_no_core_file_location)
def test_missing_core_location_file(self): """ Ensure we detect missing core location file. """ config_root = self._create_unlocalized_pipeline_configuration("missing_core_location_file") self.assertIsNone(pipelineconfig_utils.get_core_path_for_config(config_root), None) with self.assertRaisesRegexp( TankFileDoesNotExistError, "without a localized core is missing a core" ): pipelineconfig_utils.get_python_interpreter_for_config(config_root)
def test_localize_config_with_interpreter_as_env_var(self): """ Test for interpreter file in a localized config. """ config_root = self._create_pipeline_configuration( "localized_core_with_interpreter_as_env_var") # Create interpreter file for good config. self._create_interpreter_file(config_root, "$SGTK_TEST_INTERPRETER") # Patch os.path.exists since /i/wish/this/was/python3 is obviously not a real # file name. with patch("os.path.exists", return_value=True): with temp_env_var( SGTK_TEST_INTERPRETER="/i/wish/this/was/python3"): self.assertEqual( pipelineconfig_utils.get_python_interpreter_for_config( config_root), "/i/wish/this/was/python3")
def test_localize_config_with_interpreter_as_env_var(self): """ Test for interpreter file in a localized config. """ config_root = self._create_pipeline_configuration( "localized_core_with_interpreter_as_env_var" ) # Create interpreter file for good config. self._create_interpreter_file(config_root, "$SGTK_TEST_INTERPRETER") # Patch os.path.exists since /i/wish/this/was/python3 is obviously not a real # file name. with patch("os.path.exists", return_value=True): with temp_env_var(SGTK_TEST_INTERPRETER="/i/wish/this/was/python3"): self.assertEqual( pipelineconfig_utils.get_python_interpreter_for_config(config_root), "/i/wish/this/was/python3" )
def test_shared_config_interpreter_file(self): """ Test for interpreter file in a non-localized config. """ # Shared config with valid core. valid_studio_core = self._create_studio_core("valid_studio_core") self._create_interpreter_file(valid_studio_core, sys.executable) self.assertEqual( pipelineconfig_utils.get_python_interpreter_for_config( self._create_pipeline_configuration( "config_with_valid_studio_core", core_location=valid_studio_core ) ), sys.executable ) # Test shared config with a bad interpreter location. studio_core_with_bad_interpreter_location = self._create_studio_core( "studio_core_with_bad_interpreter" ) self._create_interpreter_file( studio_core_with_bad_interpreter_location, "/path/to/missing/python" ) with self.assertRaises(TankInvalidInterpreterLocationError): pipelineconfig_utils.get_python_interpreter_for_config( self._create_pipeline_configuration( "config_using_studio_core_with_bad_interpreter", core_location=studio_core_with_bad_interpreter_location ) ) # Test shared config with missing interpreter file. studio_core_with_missing_interpreter_file_location = self._create_studio_core( "studio_core_with_missing_interpreter_file" ) with self.assertRaisesRegexp(TankFileDoesNotExistError, "No interpreter file for"): pipelineconfig_utils.get_python_interpreter_for_config( self._create_pipeline_configuration( "config_using_studio_core_with_missing_interpreter_file", core_location=studio_core_with_missing_interpreter_file_location ) ) # Test with a core location that is invalid. config_with_invalid_core_location = self._create_unlocalized_pipeline_configuration( "config_with_invalid_core" ) self._create_core_file(config_with_invalid_core_location, "/path/to/missing/core") with self.assertRaises(TankInvalidCoreLocationError): pipelineconfig_utils.get_python_interpreter_for_config(config_with_invalid_core_location) # Test when the core file is missing. config_with_no_core_file_location = self._create_unlocalized_pipeline_configuration( "config_with_no_core_file" ) with self.assertRaisesRegexp(TankFileDoesNotExistError, "is missing a core location file"): pipelineconfig_utils.get_python_interpreter_for_config(config_with_no_core_file_location)