





import gc
import unittest

from transformers import MODEL_FOR_MASKED_LM_MAPPING, TF_MODEL_FOR_MASKED_LM_MAPPING, FillMaskPipeline, pipeline
from transformers.pipelines import PipelineException
from transformers.testing_utils import (
    is_pipeline_test,
    is_torch_available,
    nested_simplify,
    require_tf,
    require_torch,
    require_torch_gpu,
    slow,
)

from .test_pipelines_common import ANY
@is_pipeline_test
class     SCREAMING_SNAKE_CASE       (unittest.TestCase				):
   _UpperCamelCase   :		Dict			 =	MODEL_FOR_MASKED_LM_MAPPING
   _UpperCamelCase   :		List[Any]			 =	TF_MODEL_FOR_MASKED_LM_MAPPING


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Union[str, Any]	)->       List[str]:





     """simple docstring"""







     super().tearDown()
     # clean-up as much as possible GPU memory occupied by PyTorch
     gc.collect()
     if is_torch_available():
       import torch

       torch.cuda.empty_cache()


   @require_tf
   def 	SCREAMING_SNAKE_CASE_							(   self      :    Dict	)->       Union[str, Any]:





     """simple docstring"""







     lowercase__           =  pipeline(task='fill-mask'      ,					model='sshleifer/tiny-distilroberta-base'      ,					top_k=2      ,					framework='tf'	)
     lowercase__           =  unmasker('My name is <mask>'	)
     self.assertEqual(
         nested_simplify(snake_case__      ,					decimals=6	)      ,					[
             {'sequence': 'My name is grouped', 'score': 2.1E-0_5, 'token': 38_015, 'token_str': ' grouped'},
             {'sequence': 'My name is accuser', 'score': 2.1E-0_5, 'token': 25_506, 'token_str': ' accuser'},
         ]      ,					)

     lowercase__           =  unmasker('The largest city in France is <mask>'	)
     self.assertEqual(
         nested_simplify(snake_case__      ,					decimals=6	)      ,					[
             {
                 'sequence': 'The largest city in France is grouped',
                 'score': 2.1E-0_5,
                 'token': 38_015,
                 'token_str': ' grouped',
             },
             {
                 'sequence': 'The largest city in France is accuser',
                 'score': 2.1E-0_5,
                 'token': 25_506,
                 'token_str': ' accuser',
             },
         ]      ,					)

     lowercase__           =  unmasker('My name is <mask>'      ,					targets=[' Patrick', ' Clara', ' Teven']      ,					top_k=3	)
     self.assertEqual(
         nested_simplify(snake_case__      ,					decimals=6	)      ,					[
             {'sequence': 'My name is Clara', 'score': 2E-0_5, 'token': 13_606, 'token_str': ' Clara'},
             {'sequence': 'My name is Patrick', 'score': 2E-0_5, 'token': 3_499, 'token_str': ' Patrick'},
             {'sequence': 'My name is Te', 'score': 1.9E-0_5, 'token': 2_941, 'token_str': ' Te'},
         ]      ,					)


   @require_torch
   def 	SCREAMING_SNAKE_CASE_							(   self      :    str	)->       Union[str, Any]:





     """simple docstring"""







     lowercase__           =  pipeline(task='fill-mask'      ,					model='sshleifer/tiny-distilroberta-base'      ,					top_k=2      ,					framework='pt'	)

     lowercase__           =  unmasker('My name is <mask>'	)
     self.assertEqual(
         nested_simplify(snake_case__      ,					decimals=6	)      ,					[
             {'sequence': 'My name is Maul', 'score': 2.2E-0_5, 'token': 35_676, 'token_str': ' Maul'},
             {'sequence': 'My name isELS', 'score': 2.2E-0_5, 'token': 16_416, 'token_str': 'ELS'},
         ]      ,					)

     lowercase__           =  unmasker('The largest city in France is <mask>'	)
     self.assertEqual(
         nested_simplify(snake_case__      ,					decimals=6	)      ,					[
             {
                 'sequence': 'The largest city in France is Maul',
                 'score': 2.2E-0_5,
                 'token': 35_676,
                 'token_str': ' Maul',
             },
             {'sequence': 'The largest city in France isELS', 'score': 2.2E-0_5, 'token': 16_416, 'token_str': 'ELS'},
         ]      ,					)

     lowercase__           =  unmasker('My name is <mask>'      ,					targets=[' Patrick', ' Clara', ' Teven']      ,					top_k=3	)
     self.assertEqual(
         nested_simplify(snake_case__      ,					decimals=6	)      ,					[
             {'sequence': 'My name is Patrick', 'score': 2.1E-0_5, 'token': 3_499, 'token_str': ' Patrick'},
             {'sequence': 'My name is Te', 'score': 2E-0_5, 'token': 2_941, 'token_str': ' Te'},
             {'sequence': 'My name is Clara', 'score': 2E-0_5, 'token': 13_606, 'token_str': ' Clara'},
         ]      ,					)

     lowercase__           =  unmasker('My name is <mask> <mask>'      ,					top_k=2	)

     self.assertEqual(
         nested_simplify(snake_case__      ,					decimals=6	)      ,					[
             [
                 {
                     'score': 2.2E-0_5,
                     'token': 35_676,
                     'token_str': ' Maul',
                     'sequence': '<s>My name is Maul<mask></s>',
                 },
                 {'score': 2.2E-0_5, 'token': 16_416, 'token_str': 'ELS', 'sequence': '<s>My name isELS<mask></s>'},
             ],
             [
                 {
                     'score': 2.2E-0_5,
                     'token': 35_676,
                     'token_str': ' Maul',
                     'sequence': '<s>My name is<mask> Maul</s>',
                 },
                 {'score': 2.2E-0_5, 'token': 16_416, 'token_str': 'ELS', 'sequence': '<s>My name is<mask>ELS</s>'},
             ],
         ]      ,					)


   @require_torch_gpu
   def 	SCREAMING_SNAKE_CASE_							(   self      :    int	)->       List[Any]:





     """simple docstring"""







     lowercase__           =  pipeline('fill-mask'      ,					model='hf-internal-testing/tiny-random-distilbert'      ,					device=0      ,					framework='pt'	)

     # convert model to fp16
     pipe.model.half()

     lowercase__           =  pipe('Paris is the [MASK] of France.'	)
     # We actually don't care about the result, we just want to make sure
     # it works, meaning the float16 tensor got casted back to float32
     # for postprocessing.
     self.assertIsInstance(snake_case__      ,					snake_case__	)


   @slow
   @require_torch
   def 	SCREAMING_SNAKE_CASE_							(   self      :    Optional[int]	)->       Tuple:





     """simple docstring"""







     lowercase__           =  pipeline(task='fill-mask'      ,					model='distilroberta-base'      ,					top_k=2      ,					framework='pt'	)
     self.run_large_test(snake_case__	)


   @slow
   @require_tf
   def 	SCREAMING_SNAKE_CASE_							(   self      :    str	)->       List[Any]:





     """simple docstring"""







     lowercase__           =  pipeline(task='fill-mask'      ,					model='distilroberta-base'      ,					top_k=2      ,					framework='tf'	)
     self.run_large_test(snake_case__	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Union[str, Any]      ,					a      :    List[str]	)->       Union[str, Any]:





     """simple docstring"""







     lowercase__           =  unmasker('My name is <mask>'	)
     self.assertEqual(
         nested_simplify(snake_case__	)      ,					[
             {'sequence': 'My name is John', 'score': 0.008, 'token': 610, 'token_str': ' John'},
             {'sequence': 'My name is Chris', 'score': 0.007, 'token': 1_573, 'token_str': ' Chris'},
         ]      ,					)
     lowercase__           =  unmasker('The largest city in France is <mask>'	)
     self.assertEqual(
         nested_simplify(snake_case__	)      ,					[
             {
                 'sequence': 'The largest city in France is Paris',
                 'score': 0.251,
                 'token': 2_201,
                 'token_str': ' Paris',
             },
             {
                 'sequence': 'The largest city in France is Lyon',
                 'score': 0.214,
                 'token': 12_790,
                 'token_str': ' Lyon',
             },
         ]      ,					)

     lowercase__           =  unmasker('My name is <mask>'      ,					targets=[' Patrick', ' Clara', ' Teven']      ,					top_k=3	)
     self.assertEqual(
         nested_simplify(snake_case__	)      ,					[
             {'sequence': 'My name is Patrick', 'score': 0.005, 'token': 3_499, 'token_str': ' Patrick'},
             {'sequence': 'My name is Clara', 'score': 0.000, 'token': 13_606, 'token_str': ' Clara'},
             {'sequence': 'My name is Te', 'score': 0.000, 'token': 2_941, 'token_str': ' Te'},
         ]      ,					)


   @require_torch
   def 	SCREAMING_SNAKE_CASE_							(   self      :    List[str]	)->       Any:





     """simple docstring"""







     lowercase__           =  pipeline(task='fill-mask'      ,					model='sshleifer/tiny-distilroberta-base'      ,					framework='pt'	)
     lowercase__           =  None
     lowercase__           =  None
     self.run_pipeline_test(snake_case__      ,					[]	)


   @require_tf
   def 	SCREAMING_SNAKE_CASE_							(   self      :    List[Any]	)->       List[Any]:





     """simple docstring"""







     lowercase__           =  pipeline(task='fill-mask'      ,					model='sshleifer/tiny-distilroberta-base'      ,					framework='tf'	)
     lowercase__           =  None
     lowercase__           =  None
     self.run_pipeline_test(snake_case__      ,					[]	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Optional[Any]      ,					a      :    int      ,					a      :    List[Any]      ,					a      :    Optional[Any]	)->       int:





     """simple docstring"""







     if tokenizer is None or tokenizer.mask_token_id is None:
       self.skipTest('The provided tokenizer has no mask token, (probably reformer or wav2vec2)'	)

     lowercase__           =  FillMaskPipeline(model=snake_case__      ,					tokenizer=snake_case__	)
     lowercase__           =  [
         f"""This is another {tokenizer.mask_token} test""",
     ]
     return fill_masker, examples


   def 	SCREAMING_SNAKE_CASE_							(   self      :    str      ,					a      :    Optional[int]      ,					a      :    Dict	)->       str:





     """simple docstring"""







     lowercase__           =  fill_masker.tokenizer
     lowercase__           =  fill_masker.model

     lowercase__           =  fill_masker(
         f"""This is a {tokenizer.mask_token}"""      ,					)
     self.assertEqual(
         snake_case__      ,					[
             {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
             {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
             {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
             {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
             {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
         ]      ,					)

     lowercase__           =  fill_masker([f"""This is a {tokenizer.mask_token}"""]	)
     self.assertEqual(
         snake_case__      ,					[
             {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
             {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
             {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
             {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
             {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
         ]      ,					)

     lowercase__           =  fill_masker([f"""This is a {tokenizer.mask_token}""", f"""Another {tokenizer.mask_token} great test."""]	)
     self.assertEqual(
         snake_case__      ,					[
             [
                 {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
                 {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
                 {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
                 {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
                 {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
             ],
             [
                 {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
                 {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
                 {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
                 {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
                 {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
             ],
         ]      ,					)

     with self.assertRaises(snake_case__	):
       fill_masker([None]	)
     # No mask_token is not supported
     with self.assertRaises(snake_case__	):
       fill_masker('This is'	)

     self.run_test_top_k(snake_case__      ,					snake_case__	)
     self.run_test_targets(snake_case__      ,					snake_case__	)
     self.run_test_top_k_targets(snake_case__      ,					snake_case__	)
     self.fill_mask_with_duplicate_targets_and_top_k(snake_case__      ,					snake_case__	)
     self.fill_mask_with_multiple_masks(snake_case__      ,					snake_case__	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Union[str, Any]      ,					a      :    Optional[Any]      ,					a      :    int	)->       Tuple:





     """simple docstring"""







     lowercase__           =  tokenizer.get_vocab()
     lowercase__           =  sorted(vocab.keys()	)[:2]
     # Pipeline argument
     lowercase__           =  FillMaskPipeline(model=snake_case__      ,					tokenizer=snake_case__      ,					targets=snake_case__	)
     lowercase__           =  fill_masker(f"""This is a {tokenizer.mask_token}"""	)
     self.assertEqual(
         snake_case__      ,					[
             {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
             {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
         ]      ,					)
     lowercase__           =  {vocab[el] for el in targets}
     self.assertEqual({el['token'] for el in outputs}      ,					snake_case__	)
     lowercase__           =  [tokenizer.decode([x]	) for x in target_ids]
     self.assertEqual({el['token_str'] for el in outputs}      ,					set(snake_case__	)	)

     # Call argument
     lowercase__           =  FillMaskPipeline(model=snake_case__      ,					tokenizer=snake_case__	)
     lowercase__           =  fill_masker(f"""This is a {tokenizer.mask_token}"""      ,					targets=snake_case__	)
     self.assertEqual(
         snake_case__      ,					[
             {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
             {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
         ]      ,					)
     lowercase__           =  {vocab[el] for el in targets}
     self.assertEqual({el['token'] for el in outputs}      ,					snake_case__	)
     lowercase__           =  [tokenizer.decode([x]	) for x in target_ids]
     self.assertEqual({el['token_str'] for el in outputs}      ,					set(snake_case__	)	)

     # Score equivalence
     lowercase__           =  fill_masker(f"""This is a {tokenizer.mask_token}"""      ,					targets=snake_case__	)
     lowercase__           =  [top_mask["token_str"] for top_mask in outputs]
     lowercase__           =  [top_mask["score"] for top_mask in outputs]

     # For some BPE tokenizers, `</w>` is removed during decoding, so `token_str` won't be the same as in `targets`.
     if set(snake_case__	) == set(snake_case__	):
       lowercase__           =  fill_masker(f"""This is a {tokenizer.mask_token}"""      ,					targets=snake_case__	)
       lowercase__           =  [top_mask["score"] for top_mask in unmasked_targets]
       self.assertEqual(nested_simplify(snake_case__	)      ,					nested_simplify(snake_case__	)	)

     # Raises with invalid
     with self.assertRaises(snake_case__	):
       lowercase__           =  fill_masker(f"""This is a {tokenizer.mask_token}"""      ,					targets=[]	)
     # For some tokenizers, `""` is actually in the vocabulary and the expected error won't raised
     if "" not in tokenizer.get_vocab():
       with self.assertRaises(snake_case__	):
         lowercase__           =  fill_masker(f"""This is a {tokenizer.mask_token}"""      ,					targets=['']	)
       with self.assertRaises(snake_case__	):
         lowercase__           =  fill_masker(f"""This is a {tokenizer.mask_token}"""      ,					targets=''	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Any      ,					a      :    Union[str, Any]      ,					a      :    List[Any]	)->       int:





     """simple docstring"""







     lowercase__           =  FillMaskPipeline(model=snake_case__      ,					tokenizer=snake_case__      ,					top_k=2	)
     lowercase__           =  fill_masker(f"""This is a {tokenizer.mask_token}"""	)
     self.assertEqual(
         snake_case__      ,					[
             {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
             {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
         ]      ,					)

     lowercase__           =  FillMaskPipeline(model=snake_case__      ,					tokenizer=snake_case__	)
     lowercase__           =  fill_masker(f"""This is a {tokenizer.mask_token}"""      ,					top_k=2	)
     self.assertEqual(
         snake_case__      ,					[
             {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
             {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
         ]      ,					)
     self.assertEqual(nested_simplify(snake_case__	)      ,					nested_simplify(snake_case__	)	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Any      ,					a      :    Union[str, Any]      ,					a      :    int	)->       int:





     """simple docstring"""







     lowercase__           =  tokenizer.get_vocab()
     lowercase__           =  FillMaskPipeline(model=snake_case__      ,					tokenizer=snake_case__	)

     # top_k=2, ntargets=3
     lowercase__           =  sorted(vocab.keys()	)[:3]
     lowercase__           =  fill_masker(f"""This is a {tokenizer.mask_token}"""      ,					top_k=2      ,					targets=snake_case__	)

     # If we use the most probably targets, and filter differently, we should still
     # have the same results
     lowercase__           =  [el["token_str"] for el in sorted(snake_case__      ,					key=lambda a	: x["score"]      ,					reverse=snake_case__	)]
     # For some BPE tokenizers, `</w>` is removed during decoding, so `token_str` won't be the same as in `targets`.
     if set(snake_case__	).issubset(snake_case__	):
       lowercase__           =  fill_masker(f"""This is a {tokenizer.mask_token}"""      ,					top_k=3      ,					targets=snake_case__	)
       # They should yield exactly the same result
       self.assertEqual(nested_simplify(snake_case__	)      ,					nested_simplify(snake_case__	)	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Tuple      ,					a      :    str      ,					a      :    Optional[Any]	)->       int:





     """simple docstring"""







     lowercase__           =  FillMaskPipeline(model=snake_case__      ,					tokenizer=snake_case__	)
     lowercase__           =  tokenizer.get_vocab()
     # String duplicates + id duplicates
     lowercase__           =  sorted(vocab.keys()	)[:3]
     lowercase__           =  [targets[0], targets[1], targets[0], targets[2], targets[1]]
     lowercase__           =  fill_masker(f"""My name is {tokenizer.mask_token}"""      ,					targets=snake_case__      ,					top_k=10	)

     # The target list contains duplicates, so we can't output more
     # than them
     self.assertEqual(len(snake_case__	)      ,					3	)


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Optional[int]      ,					a      :    Tuple      ,					a      :    str	)->       List[Any]:





     """simple docstring"""







     lowercase__           =  FillMaskPipeline(model=snake_case__      ,					tokenizer=snake_case__	)

     lowercase__           =  fill_masker(
         f"""This is a {tokenizer.mask_token} {tokenizer.mask_token} {tokenizer.mask_token}"""      ,					top_k=2	)
     self.assertEqual(
         snake_case__      ,					[
             [
                 {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
                 {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
             ],
             [
                 {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
                 {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
             ],
             [
                 {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
                 {'sequence': ANY(snake_case__	), 'score': ANY(snake_case__	), 'token': ANY(snake_case__	), 'token_str': ANY(snake_case__	)},
             ],
         ]      ,					)







from datasets.utils.patching import _PatchedModuleObj, patch_submodule

from . import _test_patching




def       __UpperCamelCase  ()    ->       str:
  import os as original_os
  from os import path as original_path
  from os import rename as original_rename
  from os.path import dirname as original_dirname
  from os.path import join as original_join

  assert _test_patching.os is original_os
  assert _test_patching.path is original_path
  assert _test_patching.join is original_join

  assert _test_patching.renamed_os is original_os
  assert _test_patching.renamed_path is original_path
  assert _test_patching.renamed_join is original_join

  lowercase__           =  '__test_patch_submodule_mock__'
  with patch_submodule(_test_patching		,						'os.path.join'		,						_SCREAMING_SNAKE_CASE		):
    # Every way to access os.path.join must be patched, and the rest must stay untouched

    # check os.path.join
    assert isinstance(_test_patching.os		,						_PatchedModuleObj		)
    assert isinstance(_test_patching.os.path		,						_PatchedModuleObj		)
    assert _test_patching.os.path.join is mock

    # check path.join
    assert isinstance(_test_patching.path		,						_PatchedModuleObj		)
    assert _test_patching.path.join is mock

    # check join
    assert _test_patching.join is mock

    # check that the other attributes are untouched
    assert _test_patching.os.rename is original_rename
    assert _test_patching.path.dirname is original_dirname
    assert _test_patching.os.path.dirname is original_dirname

    # Even renamed modules or objects must be patched

    # check renamed_os.path.join
    assert isinstance(_test_patching.renamed_os		,						_PatchedModuleObj		)
    assert isinstance(_test_patching.renamed_os.path		,						_PatchedModuleObj		)
    assert _test_patching.renamed_os.path.join is mock

    # check renamed_path.join
    assert isinstance(_test_patching.renamed_path		,						_PatchedModuleObj		)
    assert _test_patching.renamed_path.join is mock

    # check renamed_join
    assert _test_patching.renamed_join is mock

    # check that the other attributes are untouched
    assert _test_patching.renamed_os.rename is original_rename
    assert _test_patching.renamed_path.dirname is original_dirname
    assert _test_patching.renamed_os.path.dirname is original_dirname

  # check that everthing is back to normal when the patch is over

  assert _test_patching.os is original_os
  assert _test_patching.path is original_path
  assert _test_patching.join is original_join

  assert _test_patching.renamed_os is original_os
  assert _test_patching.renamed_path is original_path
  assert _test_patching.renamed_join is original_join




def       __UpperCamelCase  ()    ->       Any:
  assert _test_patching.open is open

  lowercase__           =  '__test_patch_submodule_builtin_mock__'
  # _test_patching has "open" in its globals
  assert _test_patching.open is open
  with patch_submodule(_test_patching		,						'open'		,						_SCREAMING_SNAKE_CASE		):
    assert _test_patching.open is mock

  # check that everthing is back to normal when the patch is over

  assert _test_patching.open is open




def       __UpperCamelCase  ()    ->       List[str]:
  # pandas.read_csv is not present in _test_patching
  lowercase__           =  '__test_patch_submodule_missing_mock__'
  with patch_submodule(_test_patching		,						'pandas.read_csv'		,						_SCREAMING_SNAKE_CASE		):
    pass




def       __UpperCamelCase  ()    ->       List[str]:
  # builtin should always be mocked even if they're not in the globals
  # in case they're loaded at one point
  lowercase__           =  '__test_patch_submodule_missing_builtin_mock__'
  # _test_patching doesn't have "len" in its globals
  assert getattr(_test_patching		,						'len'		,						_SCREAMING_SNAKE_CASE		) is None
  with patch_submodule(_test_patching		,						'len'		,						_SCREAMING_SNAKE_CASE		):
    assert _test_patching.len is mock
  assert _test_patching.len is len




def       __UpperCamelCase  ()    ->       List[str]:
  lowercase__           =  '__test_patch_submodule_start_and_stop_mock__'
  lowercase__           =  patch_submodule(_test_patching		,						'open'		,						_SCREAMING_SNAKE_CASE		)
  assert _test_patching.open is open
  patch.start()
  assert _test_patching.open is mock
  patch.stop()
  assert _test_patching.open is open




def       __UpperCamelCase  ()    ->       Optional[int]:
  from os import rename as original_rename
  from os.path import dirname as original_dirname
  from os.path import join as original_join

  lowercase__           =  '__test_patch_submodule_successive_join__'
  lowercase__           =  '__test_patch_submodule_successive_dirname__'
  lowercase__           =  '__test_patch_submodule_successive_rename__'
  assert _test_patching.os.path.join is original_join
  assert _test_patching.os.path.dirname is original_dirname
  assert _test_patching.os.rename is original_rename

  with patch_submodule(_test_patching		,						'os.path.join'		,						_SCREAMING_SNAKE_CASE		):
    with patch_submodule(_test_patching		,						'os.rename'		,						_SCREAMING_SNAKE_CASE		):
      with patch_submodule(_test_patching		,						'os.path.dirname'		,						_SCREAMING_SNAKE_CASE		):
        assert _test_patching.os.path.join is mock_join
        assert _test_patching.os.path.dirname is mock_dirname
        assert _test_patching.os.rename is mock_rename

    # try another order
  with patch_submodule(_test_patching		,						'os.rename'		,						_SCREAMING_SNAKE_CASE		):
    with patch_submodule(_test_patching		,						'os.path.join'		,						_SCREAMING_SNAKE_CASE		):
      with patch_submodule(_test_patching		,						'os.path.dirname'		,						_SCREAMING_SNAKE_CASE		):
        assert _test_patching.os.path.join is mock_join
        assert _test_patching.os.path.dirname is mock_dirname
        assert _test_patching.os.rename is mock_rename

  assert _test_patching.os.path.join is original_join
  assert _test_patching.os.path.dirname is original_dirname
  assert _test_patching.os.rename is original_rename




def       __UpperCamelCase  ()    ->       Optional[Any]:
  lowercase__           =  '__test_patch_submodule_doesnt_exist_mock__'
  with patch_submodule(_test_patching		,						'__module_that_doesn_exist__.__attribute_that_doesn_exist__'		,						_SCREAMING_SNAKE_CASE		):
    pass
  with patch_submodule(_test_patching		,						'os.__attribute_that_doesn_exist__'		,						_SCREAMING_SNAKE_CASE		):
    pass


