code: def test_valid_vocab_extension(self):
      vocab_dir = self.TEST_DIR / "vocab_save"
      # Test: padded/non-padded common namespaces are extending appropriately
      non_padded_namespaces_list = [[], ["tokens"]]
      for non_padded_namespaces in non_padded_namespaces_list:
          original_vocab = Vocabulary(
              non_padded_namespaces=non_padded_namespaces
          )
          original_vocab.add_tokens_to_namespace(
              ["d", "a", "b"], namespace="tokens"
          )
          text_field = TextField(
              [Token(t) for t in ["a", "d", "c", "e"]],
              {"tokens": SingleIdTokenIndexer("tokens")},
          )
          vocab_dir = self.TEST_DIR / "vocab_save"
          shutil.rmtree(vocab_dir, ignore_errors=True)
          original_vocab.save_to_files(vocab_dir)
          instances = Batch([Instance({"text": text_field})])
          params = Params(
              {
                  "type": "extend",
                  "directory": vocab_dir,
                  "non_padded_namespaces": non_padded_namespaces,
              }
          )
          extended_vocab = Vocabulary.from_params(
              params, instances=instances
          )
  
          extra_count = 2 if extended_vocab.is_padded("tokens") else 0
          assert (
              extended_vocab.get_token_index("d", "tokens")
              == 0 + extra_count
          )
          assert (
              extended_vocab.get_token_index("a", "tokens")
              == 1 + extra_count
          )
          assert (
              extended_vocab.get_token_index("b", "tokens")
              == 2 + extra_count
          )
  
          assert extended_vocab.get_token_index(
              "c", "tokens"
          )  # should be present
          assert extended_vocab.get_token_index(
              "e", "tokens"
          )  # should be present
  
          assert (
              extended_vocab.get_vocab_size("tokens") == 5 + extra_count
          )
  
      # Test: padded/non-padded non-common namespaces are extending appropriately
      non_padded_namespaces_list = [
          [],
          ["tokens1"],
          ["tokens1", "tokens2"],
      ]
      for non_padded_namespaces in non_padded_namespaces_list:
          original_vocab = Vocabulary(
              non_padded_namespaces=non_padded_namespaces
          )
          original_vocab.add_token_to_namespace(
              "a", namespace="tokens1"
          )  # index2
          text_field = TextField(
              [Token(t) for t in ["b"]],
              {"tokens2": SingleIdTokenIndexer("tokens2")},
          )
          instances = Batch([Instance({"text": text_field})])
          vocab_dir = self.TEST_DIR / "vocab_save"
          shutil.rmtree(vocab_dir, ignore_errors=True)
          original_vocab.save_to_files(vocab_dir)
  
          params = Params(
              {
                  "type": "extend",
                  "directory": vocab_dir,
                  "non_padded_namespaces": non_padded_namespaces,
              }
          )
          extended_vocab = Vocabulary.from_params(
              params, instances=instances
          )
  
          # Should have two namespaces
          assert len(extended_vocab._token_to_index) == 2
  
          extra_count = 2 if extended_vocab.is_padded("tokens1") else 0
          assert (
              extended_vocab.get_vocab_size("tokens1")
              == 1 + extra_count
          )
  
          extra_count = 2 if extended_vocab.is_padded("tokens2") else 0
          assert (
              extended_vocab.get_vocab_size("tokens2")
              == 1 + extra_count
          )
  
imports: import codecs
  import gzip
  import pickle
  import shutil
  import zipfile
  from copy import deepcopy
  import pytest
  from allennlp.common.checks import ConfigurationError
  from allennlp.common.params import Params
  from allennlp.common.testing import AllenNlpTestCase
  from allennlp.data import Instance, Token
  from allennlp.data.batch import Batch
  from allennlp.data.fields import TextField
  from allennlp.data.token_indexers import SingleIdTokenIndexer, TokenCharactersIndexer
  from allennlp.data.tokenizers import CharacterTokenizer
  from allennlp.data.vocabulary import _NamespaceDependentDefaultDict, _read_pretrained_tokens, DEFAULT_OOV_TOKEN, Vocabulary
  from allennlp.modules.token_embedders.embedding import format_embeddings_file_uri
label_desc: Use image node_id 18 for calling the TestVocabulary obj's underlying member method code with example usage: obj.test_valid_vocab_extension() without return types