def test_custom_paths(): """Adding custom paths via user-config works""" user_config_path = config['USERCONFIGPATH'] package_path = pyblish.lib.main_package_path() custom_path = os.path.join(package_path, 'tests', 'plugins', 'custom') try: old_user_config_path = None if os.path.isfile(user_config_path): shutil.move(user_config_path, user_config_path + "_old") old_user_config_path = user_config_path + "_old" # Add custom path with open(user_config_path, 'w') as f: yaml.dump({'paths': [custom_path]}, f) config.reset() paths = config['paths'] assert paths plugins = pyblish.plugin.discover('validators') plugin_names = [p.__name__ for p in plugins] assert 'ValidateCustomInstance' in plugin_names finally: os.remove(user_config_path) # Restore previous config if old_user_config_path: shutil.move(old_user_config_path, user_config_path)
def test_custom_paths(): """Adding custom paths via user-config works""" user_config_path = pyblish.backend.config.USERCONFIGPATH package_path = pyblish.backend.lib.main_package_path() custom_path = os.path.join(package_path, "backend", "tests", "plugins", "custom") try: old_user_config_path = None if os.path.isfile(user_config_path): shutil.move(user_config_path, user_config_path + "_old") old_user_config_path = user_config_path + "_old" # Add custom path with open(user_config_path, "w") as f: yaml.dump({"paths": [custom_path]}, f) # Force a reload of configuration _reload_config() paths = getattr(pyblish.backend.config, "paths", None) assert paths plugins = pyblish.backend.plugin.discover("validators") plugin_names = [p.__name__ for p in plugins] assert "ValidateCustomInstance" in plugin_names finally: os.remove(user_config_path) # Restore previous config if old_user_config_path: shutil.move(old_user_config_path, user_config_path)
def test_custom_paths(): """Adding custom paths via user-config works""" user_config_path = pyblish.backend.config.USERCONFIGPATH package_path = pyblish.backend.lib.main_package_path() custom_path = os.path.join(package_path, 'backend', 'tests', 'plugins', 'custom') try: old_user_config_path = None if os.path.isfile(user_config_path): shutil.move(user_config_path, user_config_path + "_old") old_user_config_path = user_config_path + "_old" # Add custom path with open(user_config_path, 'w') as f: yaml.dump({'paths': [custom_path]}, f) # Force a reload of configuration _reload_config() paths = getattr(pyblish.backend.config, 'paths', None) assert paths plugins = pyblish.backend.plugin.discover('validators') plugin_names = [p.__name__ for p in plugins] assert 'ValidateCustomInstance' in plugin_names finally: os.remove(user_config_path) # Restore previous config if old_user_config_path: shutil.move(old_user_config_path, user_config_path)
def test_custom_data(): """Data as a side-car file works fine""" runner = CliRunner() with runner.isolated_filesystem(): with open("data.yaml", "w") as f: yaml.dump({"key": "value"}, f) runner.invoke(pyblish.cli.main, ["publish"]) assert_equals(context().data("key"), "value")
def test_user_overrides_custom(): """User configuration overrides Custom configuration""" config = pyblish.Config() user_config_path = config['USERCONFIGPATH'] os.environ[config['configuration_environment_variable']] = CONFIGPATH with open(user_config_path, 'w') as f: yaml.dump({'custom_variable': 'user value'}, f) config.reset() # Even though our custom configuration defines # this the user-configuration will override it. print config['custom_variable'] assert config['custom_variable'] == 'user value'
def test_user_config(): """User config augments default config""" config = pyblish.Config() user_config_path = config['USERCONFIGPATH'] with open(user_config_path, 'w') as f: yaml.dump({'test_variable': 'test_value'}, f) config.reset() with open(user_config_path, 'r') as f: user_config = yaml.load(f) assert user_config for key in user_config: assert key in config
def test_custom_configuration(): """Configuration as a side-car file works fine""" runner = CliRunner() with runner.isolated_filesystem(): with open("select_instances.py", "w") as f: f.write(""" import pyblish.api class SelectInstances(pyblish.api.Selector): def process_context(self, context): context.set_data("key", "value") """) with open("config.yaml", "w") as f: yaml.dump({"paths": [os.getcwd()]}, f) runner.invoke(pyblish.cli.main, ["publish"]) assert_equals(context().data("key"), "value")
def test_user_config(): """User config augments default config""" user_config_path = pyblish.backend.config.USERCONFIGPATH remove_config_file = False try: if not os.path.isfile(user_config_path): remove_config_file = True with open(user_config_path, "w") as f: yaml.dump({"test_variable": "test_value"}, f) # Force a reload of configuration _reload_config() with open(user_config_path, "r") as f: user_config = yaml.load(f) assert user_config for variable in user_config: assert getattr(pyblish.backend.config, variable, None) finally: if remove_config_file: os.remove(user_config_path)
def test_user_config(): """User config augments default config""" user_config_path = pyblish.backend.config.USERCONFIGPATH remove_config_file = False try: if not os.path.isfile(user_config_path): remove_config_file = True with open(user_config_path, 'w') as f: yaml.dump({'test_variable': 'test_value'}, f) # Force a reload of configuration _reload_config() with open(user_config_path, 'r') as f: user_config = yaml.load(f) assert user_config for variable in user_config: assert getattr(pyblish.backend.config, variable, None) finally: if remove_config_file: os.remove(user_config_path)