code: def test_caliban_config(tmpdir):
      """Tests validation of the CalibanConfig schema and the method that returns the
      parsed config.
  
      """
      valid = {"apt_packages": {"cpu": ["face"]}}
      valid_path = tmpdir.join("valid.json")
  
      with open(valid_path, "w") as f:
          json.dump(valid, f)
  
      valid_shared = {"apt_packages": ["face"]}
      valid_shared_path = tmpdir.join("valid_shared.json")
  
      with open(valid_shared_path, "w") as f:
          json.dump(valid_shared, f)
  
      invalid = {"apt_packages": "face"}
      invalid_path = tmpdir.join("invalid.json")
  
      with open(invalid_path, "w") as f:
          json.dump(invalid, f)
  
      # Failing the schema raises an error.
      with pytest.raises(us.FatalSchemaError):
          c.caliban_config(invalid_path)
  
      # paths that don't exist return an empty map:
      assert c.caliban_config("random_path") == {}
  
      # If the config is valid, c.apt_packages can fetch the packages we specified.
      config = c.caliban_config(valid_path)
      assert c.apt_packages(config, c.JobMode.GPU) == []
      assert c.apt_packages(config, c.JobMode.CPU) == ["face"]
  
      # If the user supplies a list instead of a dict, all still works well.
      valid_shared_conf = c.caliban_config(valid_shared_path)
      cpu = c.apt_packages(valid_shared_conf, c.JobMode.CPU)
      gpu = c.apt_packages(valid_shared_conf, c.JobMode.GPU)
  
      assert cpu == gpu
      assert cpu == ["face"]
  
file_path: caliban/tests/caliban/config/test_config.py
imports: import json
  import os
  from argparse import ArgumentTypeError
  import hypothesis.strategies
  from hypothesis import given
  import caliban.config
  import caliban.platform.cloud.types
  import caliban.util.schema
  import pytest
label_desc: Use image node_id 9 for calling a global function with example usage: test_caliban_config(tmpdir) without return types