old_contents: import os
  import pytest
  from user_sync.config import ConfigFileLoader
  
  
  @pytest.fixture
  def config_file(fixture_dir):
      return os.path.join(fixture_dir, 'user-sync-config.yml')
  
  
  def test_load_root(config_file):
      """Load root config file and test for presence of root-level keys"""
      config = ConfigFileLoader.load_root_config(config_file)
      assert isinstance(config, dict)
      assert ('adobe_users' in config and 'directory_users' in config and
              'logging' in config and 'limits' in config and
              'invocation_defaults' in config)
  
new_contents: import os
  import pytest
  import yaml
  import collections
  import shutil
  from user_sync.config import ConfigFileLoader, ConfigLoader
  from user_sync import app
  from user_sync.error import AssertionException
  
  
  @pytest.fixture
  def root_config_file(fixture_dir):
      return os.path.join(fixture_dir, 'user-sync-config.yml')
  
  
  @pytest.fixture
  def ldap_config_file(fixture_dir):
      return os.path.join(fixture_dir, 'connector-ldap.yml')
  
  
  @pytest.fixture
  def umapi_config_file(fixture_dir):
      return os.path.join(fixture_dir, 'connector-umapi.yml')
  
  
  @pytest.fixture
  def tmp_config_files(root_config_file, ldap_config_file, umapi_config_file, tmpdir):
      tmpfiles = []
      for fname in [root_config_file, ldap_config_file, umapi_config_file]:
          basename = os.path.split(fname)[-1]
          tmpfile = os.path.join(tmpdir, basename)
          shutil.copy(fname, tmpfile)
          tmpfiles.append(tmpfile)
      return tuple(tmpfiles)
  
  
  @pytest.fixture
  def modify_root_config(tmp_config_files):
      (root_config_file, _, _) = tmp_config_files
  
      def _modify_root_config(keys, val):
          def update(d, ks, u):
              k, ks = ks[0], ks[1:]
              v = d.get(k)
              if isinstance(v, collections.Mapping):
                  d[k] = update(v, ks, u)
              else:
                  d[k] = u
              return d
  
          conf = yaml.safe_load(open(root_config_file))
          conf = update(conf, keys, val)
          yaml.dump(conf, open(root_config_file, 'w'))
  
          return root_config_file
      return _modify_root_config
  
  
  def test_load_root(root_config_file):
      """Load root config file and test for presence of root-level keys"""
      config = ConfigFileLoader.load_root_config(root_config_file)
      assert isinstance(config, dict)
      assert ('adobe_users' in config and 'directory_users' in config and
              'logging' in config and 'limits' in config and
              'invocation_defaults' in config)
  
  
  def test_max_adobe_percentage(modify_root_config):
      root_config_file = modify_root_config(['limits', 'max_adobe_only_users'], "50%")
      config = ConfigFileLoader.load_root_config(root_config_file)
      assert ('limits' in config and 'max_adobe_only_users' in config['limits'] and
              config['limits']['max_adobe_only_users'] == "50%")
  
      args = app.process_args(['-c', root_config_file])
      options = ConfigLoader(args).get_rule_options()
      assert 'max_adobe_only_users' in options and options['max_adobe_only_users'] == '50%'
  
      modify_root_config(['limits', 'max_adobe_only_users'], "error%")
      with pytest.raises(AssertionException):
          ConfigLoader(args).get_rule_options()
  
  
  def test_additional_groups_config(modify_root_config):
      addl_groups = [
          {"source": r"ACL-(.+)", "target": r"ACL-Grp-(\1)"},
          {"source": r"(.+)-ACL", "target": r"ACL-Grp-(\1)"},
      ]
      root_config_file = modify_root_config(['directory_users', 'additional_groups'], addl_groups)
      config = ConfigFileLoader.load_root_config(root_config_file)
      assert ('additional_groups' in config['directory_users'] and
              len(config['directory_users']['additional_groups']) == 2)
  
subject: expand percentage config test and start additional groups config test