File size: 4,791 Bytes
96e9536
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# coding=utf-8
# Copyright 2023 The HuggingFace Inc. team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import sys
import unittest


git_repo_path = os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
sys.path.append(os.path.join(git_repo_path, "utils"))

import get_test_info  # noqa: E402
from get_test_info import (  # noqa: E402
    get_model_to_test_mapping,
    get_model_to_tester_mapping,
    get_test_to_tester_mapping,
)


BERT_TEST_FILE = os.path.join("tests", "models", "bert", "test_modeling_bert.py")
BLIP_TEST_FILE = os.path.join("tests", "models", "blip", "test_modeling_blip.py")


class GetTestInfoTester(unittest.TestCase):
    def test_get_test_to_tester_mapping(self):
        bert_test_tester_mapping = get_test_to_tester_mapping(BERT_TEST_FILE)
        blip_test_tester_mapping = get_test_to_tester_mapping(BLIP_TEST_FILE)

        EXPECTED_BERT_MAPPING = {"BertModelTest": "BertModelTester"}

        EXPECTED_BLIP_MAPPING = {
            "BlipModelTest": "BlipModelTester",
            "BlipTextImageModelTest": "BlipTextImageModelsModelTester",
            "BlipTextModelTest": "BlipTextModelTester",
            "BlipTextRetrievalModelTest": "BlipTextRetrievalModelTester",
            "BlipVQAModelTest": "BlipVQAModelTester",
            "BlipVisionModelTest": "BlipVisionModelTester",
        }

        self.assertEqual(get_test_info.to_json(bert_test_tester_mapping), EXPECTED_BERT_MAPPING)
        self.assertEqual(get_test_info.to_json(blip_test_tester_mapping), EXPECTED_BLIP_MAPPING)

    def test_get_model_to_test_mapping(self):
        bert_model_test_mapping = get_model_to_test_mapping(BERT_TEST_FILE)
        blip_model_test_mapping = get_model_to_test_mapping(BLIP_TEST_FILE)

        EXPECTED_BERT_MAPPING = {
            "BertForMaskedLM": ["BertModelTest"],
            "BertForMultipleChoice": ["BertModelTest"],
            "BertForNextSentencePrediction": ["BertModelTest"],
            "BertForPreTraining": ["BertModelTest"],
            "BertForQuestionAnswering": ["BertModelTest"],
            "BertForSequenceClassification": ["BertModelTest"],
            "BertForTokenClassification": ["BertModelTest"],
            "BertLMHeadModel": ["BertModelTest"],
            "BertModel": ["BertModelTest"],
        }

        EXPECTED_BLIP_MAPPING = {
            "BlipForConditionalGeneration": ["BlipTextImageModelTest"],
            "BlipForImageTextRetrieval": ["BlipTextRetrievalModelTest"],
            "BlipForQuestionAnswering": ["BlipVQAModelTest"],
            "BlipModel": ["BlipModelTest"],
            "BlipTextModel": ["BlipTextModelTest"],
            "BlipVisionModel": ["BlipVisionModelTest"],
        }

        self.assertEqual(get_test_info.to_json(bert_model_test_mapping), EXPECTED_BERT_MAPPING)
        self.assertEqual(get_test_info.to_json(blip_model_test_mapping), EXPECTED_BLIP_MAPPING)

    def test_get_model_to_tester_mapping(self):
        bert_model_tester_mapping = get_model_to_tester_mapping(BERT_TEST_FILE)
        blip_model_tester_mapping = get_model_to_tester_mapping(BLIP_TEST_FILE)

        EXPECTED_BERT_MAPPING = {
            "BertForMaskedLM": ["BertModelTester"],
            "BertForMultipleChoice": ["BertModelTester"],
            "BertForNextSentencePrediction": ["BertModelTester"],
            "BertForPreTraining": ["BertModelTester"],
            "BertForQuestionAnswering": ["BertModelTester"],
            "BertForSequenceClassification": ["BertModelTester"],
            "BertForTokenClassification": ["BertModelTester"],
            "BertLMHeadModel": ["BertModelTester"],
            "BertModel": ["BertModelTester"],
        }

        EXPECTED_BLIP_MAPPING = {
            "BlipForConditionalGeneration": ["BlipTextImageModelsModelTester"],
            "BlipForImageTextRetrieval": ["BlipTextRetrievalModelTester"],
            "BlipForQuestionAnswering": ["BlipVQAModelTester"],
            "BlipModel": ["BlipModelTester"],
            "BlipTextModel": ["BlipTextModelTester"],
            "BlipVisionModel": ["BlipVisionModelTester"],
        }

        self.assertEqual(get_test_info.to_json(bert_model_tester_mapping), EXPECTED_BERT_MAPPING)
        self.assertEqual(get_test_info.to_json(blip_model_tester_mapping), EXPECTED_BLIP_MAPPING)