





"""simple docstring"""


import gc
import unittest

import torch
from parameterized import parameterized

from diffusers import AutoencoderKL
from diffusers.utils import floats_tensor, load_hf_numpy, require_torch_gpu, slow, torch_all_close, torch_device
from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.testing_utils import enable_full_determinism

from .test_modeling_common import ModelTesterMixin, UNetTesterMixin


enable_full_determinism()



class      __SCREAMING_SNAKE_CASE    (						lowerCamelCase__		,  lowerCamelCase__		,  unittest.TestCase   ):







  '''simple docstring'''


  SCREAMING_SNAKE_CASE__							:int	     =					AutoencoderKL
  SCREAMING_SNAKE_CASE__							:List[str]	     =					"sample"
  SCREAMING_SNAKE_CASE__							:List[Any]	     =					1e-2

  @property
  def    __SCREAMING_SNAKE_CASE				(		self   :       Union[str, Any]	)		->				Any:
        _UpperCamelCase      :	str						=       4
        _UpperCamelCase      :	int						=       3
        _UpperCamelCase      :	List[Any]						=       (32, 32)

        _UpperCamelCase      :	Tuple						=       floats_tensor((batch_size, num_channels) + sizes	).to(__lowerCamelCase	)

        return {"sample": image}

  @property
  def    __SCREAMING_SNAKE_CASE				(		self   :       Dict	)		->				Optional[int]:
        return (3, 32, 32)

  @property
  def    __SCREAMING_SNAKE_CASE				(		self   :       str	)		->				str:
        return (3, 32, 32)

  def    __SCREAMING_SNAKE_CASE				(		self   :       Tuple	)		->				Dict:
        _UpperCamelCase      :	int						=       {
            '''block_out_channels''': [32, 64],
            '''in_channels''': 3,
            '''out_channels''': 3,
            '''down_block_types''': ['''DownEncoderBlock2D''', '''DownEncoderBlock2D'''],
            '''up_block_types''': ['''UpDecoderBlock2D''', '''UpDecoderBlock2D'''],
            '''latent_channels''': 4,
        }
        _UpperCamelCase      :	str						=       self.dummy_input
        return init_dict, inputs_dict

  def    __SCREAMING_SNAKE_CASE				(		self   :       List[str]	)		->				List[str]:
        pass

  def    __SCREAMING_SNAKE_CASE				(		self   :       List[Any]	)		->				Any:
        pass

  @unittest.skipIf(torch_device == "mps"					,   "Gradient checkpointing skipped on MPS"	)
  def    __SCREAMING_SNAKE_CASE				(		self   :       List[str]	)		->				Dict:
        _UpperCamelCase      :	int						=       self.prepare_init_args_and_inputs_for_common()
        _UpperCamelCase      :	Tuple						=       self.model_class(**__lowerCamelCase	)
        model.to(__lowerCamelCase	)

        assert not model.is_gradient_checkpointing and model.training

        _UpperCamelCase      :	Tuple						=       model(**__lowerCamelCase	).sample
        # run the backwards pass on the model. For backwards pass, for simplicity purpose,
        # we won't calculate the loss and rather backprop on out.sum()
        model.zero_grad()

        _UpperCamelCase      :	Optional[Any]						=       torch.randn_like(__lowerCamelCase	)
        _UpperCamelCase      :	Tuple						=       (out - labels).mean()
        loss.backward()

        # re-instantiate the model now enabling gradient checkpointing
        _UpperCamelCase      :	str						=       self.model_class(**__lowerCamelCase	)
        # clone model
        model_a.load_state_dict(model.state_dict()	)
        model_a.to(__lowerCamelCase	)
        model_a.enable_gradient_checkpointing()

        assert model_a.is_gradient_checkpointing and model_a.training

        _UpperCamelCase      :	Dict						=       model_a(**__lowerCamelCase	).sample
        # run the backwards pass on the model. For backwards pass, for simplicity purpose,
        # we won't calculate the loss and rather backprop on out.sum()
        model_a.zero_grad()
        _UpperCamelCase      :	Any						=       (out_a - labels).mean()
        loss_a.backward()

        # compare the output and parameters gradients
        self.assertTrue((loss - loss_a).abs() < 1e-5	)
        _UpperCamelCase      :	List[str]						=       dict(model.named_parameters()	)
        _UpperCamelCase      :	Optional[Any]						=       dict(model_a.named_parameters()	)
        for name, param in named_params.items():
              self.assertTrue(torch_all_close(param.grad.data					,   named_params_a[name].grad.data					,   atol=5e-5	)	)

  def    __SCREAMING_SNAKE_CASE				(		self   :       Optional[int]	)		->				List[str]:
        _UpperCamelCase      :	str						=       AutoencoderKL.from_pretrained("fusing/autoencoder-kl-dummy"					,   output_loading_info=__lowerCamelCase	)
        self.assertIsNotNone(__lowerCamelCase	)
        self.assertEqual(len(loading_info["missing_keys"]	)					,   0	)

        model.to(__lowerCamelCase	)
        _UpperCamelCase      :	Optional[int]						=       model(**self.dummy_input	)

        assert image is not None, "Make sure output is not None"


  def    __SCREAMING_SNAKE_CASE				(		self   :       List[Any]	)		->				Optional[int]:
        _UpperCamelCase      :	str						=       AutoencoderKL.from_pretrained("fusing/autoencoder-kl-dummy"	)
        _UpperCamelCase      :	Tuple						=       model.to(__lowerCamelCase	)
        model.eval()

        if torch_device == "mps":
              _UpperCamelCase      :	Union[str, Any]						=       torch.manual_seed(0	)
        else:
              _UpperCamelCase      :	Any						=       torch.Generator(device=__lowerCamelCase	).manual_seed(0	)

        _UpperCamelCase      :	Optional[int]						=       torch.randn(
            1					,   model.config.in_channels					,   model.config.sample_size					,   model.config.sample_size					,   generator=torch.manual_seed(0	)					,   )
        _UpperCamelCase      :	Dict						=       image.to(__lowerCamelCase	)
        with torch.no_grad():
              _UpperCamelCase      :	List[Any]						=       model(__lowerCamelCase					,   sample_posterior=__lowerCamelCase					,   generator=__lowerCamelCase	).sample

        _UpperCamelCase      :	Optional[Any]						=       output[0, -1, -3:, -3:].flatten().cpu()

        # Since the VAE Gaussian prior's generator is seeded on the appropriate device,
        # the expected output slices are not the same for CPU and GPU.
        if torch_device == "mps":
              _UpperCamelCase      :	List[str]						=       torch.tensor(
                  [
                      -4.0_0_7_8e-0_1,
                      -3.8_3_2_3e-0_4,
                      -1.2_6_8_1e-0_1,
                      -1.1_4_6_2e-0_1,
                      2.0_0_9_5e-0_1,
                      1.0_8_9_3e-0_1,
                      -8.8_2_4_7e-0_2,
                      -3.0_3_6_1e-0_1,
                      -9.8_6_4_4e-0_3,
                  ]	)
        elif torch_device == "cpu":
              _UpperCamelCase      :	str						=       torch.tensor(
                  [-0.13_52, 0.08_78, 0.04_19, -0.08_18, -0.10_69, 0.06_88, -0.14_58, -0.44_46, -0.00_26]	)
        else:
              _UpperCamelCase      :	Any						=       torch.tensor(
                  [-0.24_21, 0.46_42, 0.25_07, -0.04_38, 0.06_82, 0.31_60, -0.20_18, -0.07_27, 0.24_85]	)

        self.assertTrue(torch_all_close(__lowerCamelCase					,   __lowerCamelCase					,   rtol=1e-2	)	)





@slow
class      __SCREAMING_SNAKE_CASE    (						unittest.TestCase   ):







  '''simple docstring'''


  def    __SCREAMING_SNAKE_CASE				(		self   :       List[str]					,   __a   :       Union[str, Any]					,   __a   :       str	)		->				List[Any]:
        return F'''gaussian_noise_s={seed}_shape={'_'.join([str(__lowerCamelCase	) for s in shape]	)}.npy'''

  def    __SCREAMING_SNAKE_CASE				(		self   :       Union[str, Any]	)		->				Dict:
        super().tearDown()
        gc.collect()
        torch.cuda.empty_cache()

  def    __SCREAMING_SNAKE_CASE				(		self   :       int					,   __a   :       Union[str, Any]=0					,   __a   :       Tuple=(4, 3, 512, 512)					,   __a   :       Tuple=False	)		->				Any:
        _UpperCamelCase      :	Optional[int]						=       torch.floataa if fpaa else torch.floataa
        _UpperCamelCase      :	Dict						=       torch.from_numpy(load_hf_numpy(self.get_file_format(__lowerCamelCase					,   __lowerCamelCase	)	)	).to(__lowerCamelCase	).to(__lowerCamelCase	)
        return image

  def    __SCREAMING_SNAKE_CASE				(		self   :       List[str]					,   __a   :       Dict="CompVis/stable-diffusion-v1-4"					,   __a   :       int=False	)		->				List[str]:
        _UpperCamelCase      :	Dict						=       '''fp16''' if fpaa else None
        _UpperCamelCase      :	Optional[Any]						=       torch.floataa if fpaa else torch.floataa

        _UpperCamelCase      :	List[Any]						=       AutoencoderKL.from_pretrained(
            __lowerCamelCase					,   subfolder="vae"					,   torch_dtype=__lowerCamelCase					,   revision=__lowerCamelCase					,   )
        model.to(__lowerCamelCase	).eval()

        return model

  def    __SCREAMING_SNAKE_CASE				(		self   :       Optional[int]					,   __a   :       Optional[Any]=0	)		->				str:






        if torch_device == "mps":
              return torch.manual_seed(__lowerCamelCase	)
        return torch.Generator(device=__lowerCamelCase	).manual_seed(__lowerCamelCase	)

  @parameterized.expand(
      [
          # fmt: off
          [33, [-0.16_03, 0.98_78, -0.04_95, -0.07_90, -0.27_09, 0.83_75, -0.20_60, -0.08_24], [-0.23_95, 0.00_98, 0.01_02, -0.07_09, -0.28_40, -0.02_74, -0.07_18, -0.18_24]],
          [47, [-0.23_76, 0.11_68, 0.13_32, -0.48_40, -0.25_08, -0.07_91, -0.04_93, -0.40_89], [0.03_50, 0.08_47, 0.04_67, 0.03_44, -0.08_42, -0.05_47, -0.06_33, -0.11_31]],
          # fmt: on
      ]	)
  def    __SCREAMING_SNAKE_CASE				(		self   :       Dict					,   __a   :       int					,   __a   :       int					,   __a   :       List[Any]	)		->				Union[str, Any]:
        _UpperCamelCase      :	Optional[int]						=       self.get_sd_vae_model()
        _UpperCamelCase      :	Any						=       self.get_sd_image(__lowerCamelCase	)
        _UpperCamelCase      :	List[str]						=       self.get_generator(__lowerCamelCase	)

        with torch.no_grad():
              _UpperCamelCase      :	Dict						=       model(__lowerCamelCase					,   generator=__lowerCamelCase					,   sample_posterior=__lowerCamelCase	).sample

        assert sample.shape == image.shape

        _UpperCamelCase      :	Optional[Any]						=       sample[-1, -2:, -2:, :2].flatten().float().cpu()
        _UpperCamelCase      :	Any						=       torch.tensor(expected_slice_mps if torch_device == "mps" else expected_slice	)

        assert torch_all_close(__lowerCamelCase					,   __lowerCamelCase					,   atol=3e-3	)

  @parameterized.expand(
      [
          # fmt: off
          [33, [-0.05_13, 0.02_89, 1.37_99, 0.21_66, -0.25_73, -0.08_71, 0.51_03, -0.09_99]],
          [47, [-0.41_28, -0.13_20, -0.37_04, 0.19_65, -0.41_16, -0.23_32, -0.33_40, 0.22_47]],
          # fmt: on
      ]	)
  @require_torch_gpu
  def    __SCREAMING_SNAKE_CASE				(		self   :       Tuple					,   __a   :       List[Any]					,   __a   :       str	)		->				Dict:
        _UpperCamelCase      :	Union[str, Any]						=       self.get_sd_vae_model(fpaa=__lowerCamelCase	)
        _UpperCamelCase      :	List[str]						=       self.get_sd_image(__lowerCamelCase					,   fpaa=__lowerCamelCase	)
        _UpperCamelCase      :	List[Any]						=       self.get_generator(__lowerCamelCase	)

        with torch.no_grad():
              _UpperCamelCase      :	Optional[Any]						=       model(__lowerCamelCase					,   generator=__lowerCamelCase					,   sample_posterior=__lowerCamelCase	).sample

        assert sample.shape == image.shape

        _UpperCamelCase      :	Optional[Any]						=       sample[-1, -2:, :2, -2:].flatten().float().cpu()
        _UpperCamelCase      :	Any						=       torch.tensor(__lowerCamelCase	)

        assert torch_all_close(__lowerCamelCase					,   __lowerCamelCase					,   atol=1e-2	)

  @parameterized.expand(
      [
          # fmt: off
          [33, [-0.16_09, 0.98_66, -0.04_87, -0.07_77, -0.27_16, 0.83_68, -0.20_55, -0.08_14], [-0.23_95, 0.00_98, 0.01_02, -0.07_09, -0.28_40, -0.02_74, -0.07_18, -0.18_24]],
          [47, [-0.23_77, 0.11_47, 0.13_33, -0.48_41, -0.25_06, -0.08_05, -0.04_91, -0.40_85], [0.03_50, 0.08_47, 0.04_67, 0.03_44, -0.08_42, -0.05_47, -0.06_33, -0.11_31]],
          # fmt: on
      ]	)
  def    __SCREAMING_SNAKE_CASE				(		self   :       List[str]					,   __a   :       Tuple					,   __a   :       Any					,   __a   :       Any	)		->				Optional[Any]:
        _UpperCamelCase      :	int						=       self.get_sd_vae_model()
        _UpperCamelCase      :	Dict						=       self.get_sd_image(__lowerCamelCase	)

        with torch.no_grad():
              _UpperCamelCase      :	Tuple						=       model(__lowerCamelCase	).sample

        assert sample.shape == image.shape

        _UpperCamelCase      :	Dict						=       sample[-1, -2:, -2:, :2].flatten().float().cpu()
        _UpperCamelCase      :	List[Any]						=       torch.tensor(expected_slice_mps if torch_device == "mps" else expected_slice	)

        assert torch_all_close(__lowerCamelCase					,   __lowerCamelCase					,   atol=3e-3	)

  @parameterized.expand(
      [
          # fmt: off
          [13, [-0.20_51, -0.18_03, -0.23_11, -0.21_14, -0.32_92, -0.35_74, -0.29_53, -0.33_23]],
          [37, [-0.26_32, -0.26_25, -0.21_99, -0.27_41, -0.45_39, -0.49_90, -0.37_20, -0.49_25]],
          # fmt: on
      ]	)
  @require_torch_gpu
  def    __SCREAMING_SNAKE_CASE				(		self   :       Optional[Any]					,   __a   :       Dict					,   __a   :       List[str]	)		->				Any:
        _UpperCamelCase      :	Tuple						=       self.get_sd_vae_model()
        _UpperCamelCase      :	Union[str, Any]						=       self.get_sd_image(__lowerCamelCase					,   shape=(3, 4, 64, 64)	)

        with torch.no_grad():
              _UpperCamelCase      :	str						=       model.decode(__lowerCamelCase	).sample

        assert list(sample.shape	) == [3, 3, 512, 512]

        _UpperCamelCase      :	Dict						=       sample[-1, -2:, :2, -2:].flatten().cpu()
        _UpperCamelCase      :	Any						=       torch.tensor(__lowerCamelCase	)

        assert torch_all_close(__lowerCamelCase					,   __lowerCamelCase					,   atol=1e-3	)

  @parameterized.expand(
      [
          # fmt: off
          [27, [-0.03_69, 0.02_07, -0.07_76, -0.06_82, -0.17_47, -0.19_30, -0.14_65, -0.20_39]],
          [16, [-0.16_28, -0.21_34, -0.27_47, -0.26_42, -0.37_74, -0.44_04, -0.36_87, -0.42_77]],
          # fmt: on
      ]	)
  @require_torch_gpu
  def    __SCREAMING_SNAKE_CASE				(		self   :       str					,   __a   :       Tuple					,   __a   :       str	)		->				Optional[int]:
        _UpperCamelCase      :	Any						=       self.get_sd_vae_model(fpaa=__lowerCamelCase	)
        _UpperCamelCase      :	Dict						=       self.get_sd_image(__lowerCamelCase					,   shape=(3, 4, 64, 64)					,   fpaa=__lowerCamelCase	)

        with torch.no_grad():
              _UpperCamelCase      :	Optional[Any]						=       model.decode(__lowerCamelCase	).sample

        assert list(sample.shape	) == [3, 3, 512, 512]

        _UpperCamelCase      :	Dict						=       sample[-1, -2:, :2, -2:].flatten().float().cpu()
        _UpperCamelCase      :	Union[str, Any]						=       torch.tensor(__lowerCamelCase	)

        assert torch_all_close(__lowerCamelCase					,   __lowerCamelCase					,   atol=5e-3	)

  @parameterized.expand([(13,), (16,), (27,)]	)
  @require_torch_gpu
  @unittest.skipIf(not is_xformers_available()					,   reason="xformers is not required when using PyTorch 2.0."	)
  def    __SCREAMING_SNAKE_CASE				(		self   :       Dict					,   __a   :       Union[str, Any]	)		->				Any:
        _UpperCamelCase      :	Any						=       self.get_sd_vae_model(fpaa=__lowerCamelCase	)
        _UpperCamelCase      :	str						=       self.get_sd_image(__lowerCamelCase					,   shape=(3, 4, 64, 64)					,   fpaa=__lowerCamelCase	)

        with torch.no_grad():
              _UpperCamelCase      :	Any						=       model.decode(__lowerCamelCase	).sample

        model.enable_xformers_memory_efficient_attention()
        with torch.no_grad():
              _UpperCamelCase      :	Optional[Any]						=       model.decode(__lowerCamelCase	).sample

        assert list(sample.shape	) == [3, 3, 512, 512]

        assert torch_all_close(__lowerCamelCase					,   __lowerCamelCase					,   atol=1e-1	)

  @parameterized.expand([(13,), (16,), (37,)]	)
  @require_torch_gpu
  @unittest.skipIf(not is_xformers_available()					,   reason="xformers is not required when using PyTorch 2.0."	)
  def    __SCREAMING_SNAKE_CASE				(		self   :       Union[str, Any]					,   __a   :       Tuple	)		->				Optional[Any]:
        _UpperCamelCase      :	Optional[int]						=       self.get_sd_vae_model()
        _UpperCamelCase      :	Dict						=       self.get_sd_image(__lowerCamelCase					,   shape=(3, 4, 64, 64)	)

        with torch.no_grad():
              _UpperCamelCase      :	Tuple						=       model.decode(__lowerCamelCase	).sample

        model.enable_xformers_memory_efficient_attention()
        with torch.no_grad():
              _UpperCamelCase      :	Optional[Any]						=       model.decode(__lowerCamelCase	).sample

        assert list(sample.shape	) == [3, 3, 512, 512]

        assert torch_all_close(__lowerCamelCase					,   __lowerCamelCase					,   atol=1e-2	)


  @parameterized.expand(
      [
          # fmt: off
          [33, [-0.30_01, 0.09_18, -2.69_84, -3.97_20, -3.20_99, -5.03_53, 1.73_38, -0.20_65, 3.42_67]],
          [47, [-1.50_30, -4.38_71, -6.03_55, -9.11_57, -1.66_61, -2.78_53, 2.16_07, -5.08_23, 2.56_33]],
          # fmt: on
      ]	)
  def    __SCREAMING_SNAKE_CASE				(		self   :       str					,   __a   :       List[Any]					,   __a   :       Optional[int]	)		->				List[str]:
        _UpperCamelCase      :	Tuple						=       self.get_sd_vae_model()
        _UpperCamelCase      :	Tuple						=       self.get_sd_image(__lowerCamelCase	)
        _UpperCamelCase      :	Optional[Any]						=       self.get_generator(__lowerCamelCase	)

        with torch.no_grad():
              _UpperCamelCase      :	List[Any]						=       model.encode(__lowerCamelCase	).latent_dist
              _UpperCamelCase      :	int						=       dist.sample(generator=__lowerCamelCase	)

        assert list(sample.shape	) == [image.shape[0], 4] + [i // 8 for i in image.shape[2:]]

        _UpperCamelCase      :	Optional[int]						=       sample[0, -1, -3:, -3:].flatten().cpu()
        _UpperCamelCase      :	int						=       torch.tensor(__lowerCamelCase	)

        _UpperCamelCase      :	Any						=       3e-3 if torch_device != '''mps''' else 1e-2
        assert torch_all_close(__lowerCamelCase					,   __lowerCamelCase					,   atol=__lowerCamelCase	)











"""simple docstring"""


import importlib
import os
import sys


# This is required to make the module import works (when the python process is running from the root of the repo)
sys.path.append(".")




def 					lowercase__    (					lowercase_			)					->		int:




      """simple docstring"""

      _UpperCamelCase      :	Any						=       test_file.split(os.path.sep			)
      if components[0:2] != ["tests", "models"]:
            raise ValueError(
                "`test_file` should start with `tests/models/` (with `/` being the OS specific path separator). Got "
                F'''{test_file} instead.'''			)
      _UpperCamelCase      :	str						=       components[-1]
      if not test_fn.endswith("py"			):
            raise ValueError(F'''`test_file` should be a python file. Got {test_fn} instead.'''			)
      if not test_fn.startswith("test_modeling_"			):
            raise ValueError(
                F'''`test_file` should point to a file name of the form `test_modeling_*.py`. Got {test_fn} instead.'''			)

      _UpperCamelCase      :	Dict						=       components[:-1] + [test_fn.replace(".py"		,""			)]
      _UpperCamelCase      :	List[str]						=       ".".join(lowercase_			)

      return test_module_path




def 					lowercase__    (					lowercase_			)					->		List[Any]:




      """simple docstring"""

      _UpperCamelCase      :	Optional[Any]						=       get_module_path(lowercase_			)
      _UpperCamelCase      :	str						=       importlib.import_module(lowercase_			)

      return test_module




def 					lowercase__    (					lowercase_			)					->		Optional[Any]:




      """simple docstring"""

      _UpperCamelCase      :	Union[str, Any]						=       []
      _UpperCamelCase      :	List[Any]						=       get_test_module(lowercase_			)
      for attr in dir(lowercase_			):
            if attr.endswith("ModelTester"			):
                  tester_classes.append(getattr(lowercase_		,lowercase_			)			)

    # sort with class names
      return sorted(lowercase_		,key=lambda lowercase_			: x.__name__			)




def 					lowercase__    (					lowercase_			)					->		Tuple:




      """simple docstring"""

      _UpperCamelCase      :	Optional[Any]						=       []
      _UpperCamelCase      :	Any						=       get_test_module(lowercase_			)
      for attr in dir(lowercase_			):
            _UpperCamelCase      :	int						=       getattr(lowercase_		,lowercase_			)
            # (TF/Flax)ModelTesterMixin is also an attribute in specific model test module. Let's exclude them by checking
            # `all_model_classes` is not empty (which also excludes other special classes).
            _UpperCamelCase      :	Optional[Any]						=       getattr(lowercase_		,"all_model_classes"		,[]			)
            if len(lowercase_			) > 0:
                  test_classes.append(lowercase_			)

    # sort with class names
      return sorted(lowercase_		,key=lambda lowercase_			: x.__name__			)




def 					lowercase__    (					lowercase_			)					->		Any:




      """simple docstring"""

      _UpperCamelCase      :	Dict						=       get_test_classes(lowercase_			)
      _UpperCamelCase      :	int						=       set()
      for test_class in test_classes:
            model_classes.update(test_class.all_model_classes			)

      # sort with class names
      return sorted(lowercase_		,key=lambda lowercase_			: x.__name__			)




def 					lowercase__    (					lowercase_			)					->		Optional[Any]:




      """simple docstring"""

      _UpperCamelCase      :	List[str]						=       test_class()
      if hasattr(lowercase_		,"setUp"			):
            test.setUp()

      _UpperCamelCase      :	Tuple						=       None
      if hasattr(lowercase_		,"model_tester"			):
            # `(TF/Flax)ModelTesterMixin` has this attribute default to `None`. Let's skip this case.
            if test.model_tester is not None:
                  _UpperCamelCase      :	Tuple						=       test.model_tester.__class__

      return model_tester




def 					lowercase__    (					lowercase_		,lowercase_			)					->		Union[str, Any]:




      """simple docstring"""

      _UpperCamelCase      :	str						=       get_test_classes(lowercase_			)

      _UpperCamelCase      :	Dict						=       []
      for test_class in test_classes:
            if model_class in test_class.all_model_classes:
                  target_test_classes.append(lowercase_			)

    # sort with class names
      return sorted(lowercase_		,key=lambda lowercase_			: x.__name__			)




def 					lowercase__    (					lowercase_		,lowercase_			)					->		Dict:




      """simple docstring"""

      _UpperCamelCase      :	Any						=       get_test_classes_for_model(lowercase_		,lowercase_			)

      _UpperCamelCase      :	List[Any]						=       []
      for test_class in test_classes:
            _UpperCamelCase      :	List[Any]						=       get_model_tester_from_test_class(lowercase_			)
            if tester_class is not None:
                  tester_classes.append(lowercase_			)

    # sort with class names
      return sorted(lowercase_		,key=lambda lowercase_			: x.__name__			)




def 					lowercase__    (					lowercase_			)					->		Union[str, Any]:




      """simple docstring"""

      _UpperCamelCase      :	Any						=       get_test_classes(lowercase_			)
      _UpperCamelCase      :	Tuple						=       {test_class: get_model_tester_from_test_class(lowercase_			) for test_class in test_classes}
      return test_tester_mapping




def 					lowercase__    (					lowercase_			)					->		Union[str, Any]:




      """simple docstring"""

      _UpperCamelCase      :	List[Any]						=       get_model_classes(lowercase_			)
      _UpperCamelCase      :	Optional[int]						=       {
          model_class: get_test_classes_for_model(lowercase_		,lowercase_			) for model_class in model_classes
      }
      return model_test_mapping




def 					lowercase__    (					lowercase_			)					->		Union[str, Any]:




      """simple docstring"""

      _UpperCamelCase      :	Optional[Any]						=       get_model_classes(lowercase_			)
      _UpperCamelCase      :	Tuple						=       {
          model_class: get_tester_classes_for_model(lowercase_		,lowercase_			) for model_class in model_classes
      }
      return model_to_tester_mapping




def 					lowercase__    (					lowercase_			)					->		Optional[int]:




      """simple docstring"""

      if isinstance(lowercase_		,lowercase_			):
            return o
      elif isinstance(lowercase_		,lowercase_			):
            return o.__name__
      elif isinstance(lowercase_		,(list, tuple)			):
            return [to_json(lowercase_			) for x in o]
      elif isinstance(lowercase_		,lowercase_			):
            return {to_json(lowercase_			): to_json(lowercase_			) for k, v in o.items()}
      else:
            return o
