code: def test_Providers_from_config__files(
      sysdir=None, userdir=None, dsdir=None
  ):
      """Test configuration file precedence
  
      Ensure that provider precedence works in the correct order:
  
          datalad defaults < dataset defaults < system defaults < user defaults
      """
  
      # Test the default, this is an arbitrary provider used from another
      # test
      providers = Providers.from_config_files(reload=True)
      provider = providers.get_provider("https://crcns.org/data....")
      assert_equal(provider.name, "crcns")
  
      # Test that the dataset provider overrides the datalad
      # default
      with chpwd(dsdir):
          providers = Providers.from_config_files(reload=True)
          provider = providers.get_provider(
              "https://crcns.org/data...."
          )
          assert_equal(provider.name, "dscrcns")
  
          # Test that the system defaults take precedence over the dataset
          # defaults (we're still within the dsdir)
          with patch.multiple(
              "platformdirs.AppDirs",
              site_config_dir=sysdir,
              user_config_dir=None,
          ):
              providers = Providers.from_config_files(reload=True)
              provider = providers.get_provider(
                  "https://crcns.org/data...."
              )
              assert_equal(provider.name, "syscrcns")
  
          # Test that the user defaults take precedence over the system
          # defaults
          with patch.multiple(
              "platformdirs.AppDirs",
              site_config_dir=sysdir,
              user_config_dir=userdir,
          ):
              providers = Providers.from_config_files(reload=True)
              provider = providers.get_provider(
                  "https://crcns.org/data...."
              )
              assert_equal(provider.name, "usercrcns")
  
file_path: datalad/datalad/downloaders/tests/test_providers.py
imports: import logging
  import os.path
  from unittest.mock import patch
  from ...support.external_versions import external_versions
  from ...tests.utils_pytest import assert_equal, assert_false, assert_greater, assert_in, assert_raises, ok_exists, swallow_logs, with_tempfile, with_testsui, with_tree
  from ...utils import chpwd, create_tree
  from ..providers import HTTPDownloader, Provider, Providers
label_desc: Use image node_id 5 for calling a global function with example usage: test_Providers_from_config__files(sysdir, userdir, dsdir) without return types