Best Python code snippet using slash
test_suite.py
Source:test_suite.py  
1# Copyright 2021 Sony Semiconductors Israel, Inc. All rights reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7#     http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14# ==============================================================================15#  ----------------- Unit test framework16import importlib17import unittest18#  ----------------  Individual test suites19from tests.common_tests.function_tests.test_histogram_collector import TestHistogramCollector20from tests.common_tests.function_tests.test_collectors_manipulation import TestCollectorsManipulations21from tests.common_tests.function_tests.test_threshold_selection import TestThresholdSelection22from tests.common_tests.function_tests.test_folder_image_loader import TestFolderLoader23from tests.common_tests.test_tp_model import TargetPlatformModelingTest, OpsetTest, QCOptionsTest, FusingTest24found_tf = importlib.util.find_spec("tensorflow") is not None and importlib.util.find_spec(25    "tensorflow_model_optimization") is not None26found_pytorch = importlib.util.find_spec("torch") is not None and importlib.util.find_spec(27    "torchvision") is not None28if found_tf:29    import tensorflow as tf30    from tests.keras_tests.feature_networks_tests.test_features_runner import FeatureNetworkTest31    from tests.keras_tests.function_tests.test_quantization_configurations import TestQuantizationConfigurations32    from tests.keras_tests.function_tests.test_tensorboard_writer import TestLogger33    from tests.keras_tests.function_tests.test_lut_quanitzer_params import TestLUTQuantizerParams34    from tests.keras_tests.function_tests.test_lp_search_bitwidth import TestLpSearchBitwidth, \35        TestSearchBitwidthConfiguration36    from tests.keras_tests.function_tests.test_bn_info_collection import TestBNInfoCollection37    from tests.keras_tests.graph_tests.test_graph_reading import TestGraphReading38    from tests.keras_tests.graph_tests.test_graph_quantization_and_export import TestTFLiteExport39    from tests.keras_tests.layer_tests.test_layers_runner import LayerTest as TFLayerTest40    from tests.keras_tests.function_tests.test_symmetric_threshold_selection_weights import \41        TestSymmetricThresholdSelectionWeights42    from tests.keras_tests.function_tests.test_uniform_quantize_tensor import TestUniformQuantizeTensor43    from tests.keras_tests.function_tests.test_uniform_range_selection_weights import TestUniformRangeSelectionWeights44    from tests.keras_tests.test_keras_tp_model import TestKerasTPModel45    from tests.keras_tests.function_tests.test_sensitivity_metric_interest_points import \46        TestSensitivityMetricInterestPoints47if found_pytorch:48    from tests.pytorch_tests.layer_tests.test_layers_runner import LayerTest as TorchLayerTest49    from tests.pytorch_tests.model_tests.test_feature_models_runner import FeatureModelsTestRunner50    from tests.pytorch_tests.model_tests.test_models_runner import ModelTest51    from tests.pytorch_tests.function_tests.test_function_runner import FunctionTestRunner52    from tests.pytorch_tests.test_pytorch_tp_model import TestPytorchTPModel53if __name__ == '__main__':54    # -----------------  Load all the test cases55    suiteList = []56    suiteList.append(unittest.TestLoader().loadTestsFromTestCase(TestHistogramCollector))57    suiteList.append(unittest.TestLoader().loadTestsFromTestCase(TestCollectorsManipulations))58    suiteList.append(unittest.TestLoader().loadTestsFromTestCase(TestFolderLoader))59    suiteList.append(unittest.TestLoader().loadTestsFromTestCase(TestThresholdSelection))60    suiteList.append(unittest.TestLoader().loadTestsFromTestCase(TargetPlatformModelingTest))61    suiteList.append(unittest.TestLoader().loadTestsFromTestCase(OpsetTest))62    suiteList.append(unittest.TestLoader().loadTestsFromTestCase(QCOptionsTest))63    suiteList.append(unittest.TestLoader().loadTestsFromTestCase(FusingTest))64    # Add TF tests only if tensorflow is installed65    if found_tf:66        suiteList.append(unittest.TestLoader().loadTestsFromTestCase(TestSensitivityMetricInterestPoints))67        suiteList.append(unittest.TestLoader().loadTestsFromTestCase(TestQuantizationConfigurations))68        suiteList.append(unittest.TestLoader().loadTestsFromTestCase(FeatureNetworkTest))69        suiteList.append(unittest.TestLoader().loadTestsFromTestCase(TestLogger))70        suiteList.append(unittest.TestLoader().loadTestsFromTestCase(TestLpSearchBitwidth))71        suiteList.append(unittest.TestLoader().loadTestsFromTestCase(TestSearchBitwidthConfiguration))72        suiteList.append(unittest.TestLoader().loadTestsFromTestCase(TestBNInfoCollection))73        suiteList.append(unittest.TestLoader().loadTestsFromTestCase(TestLUTQuantizerParams))74        suiteList.append(unittest.TestLoader().loadTestsFromTestCase(TestGraphReading))75        suiteList.append(unittest.TestLoader().loadTestsFromTestCase(TestTFLiteExport))76        suiteList.append(unittest.TestLoader().loadTestsFromTestCase(TestSymmetricThresholdSelectionWeights))77        suiteList.append(unittest.TestLoader().loadTestsFromTestCase(TestUniformQuantizeTensor))78        suiteList.append(unittest.TestLoader().loadTestsFromTestCase(TestUniformRangeSelectionWeights))79        suiteList.append(unittest.TestLoader().loadTestsFromTestCase(TestKerasTPModel))80        # Keras test layers are supported in TF2.6 or higher versions81        if tf.__version__ >= "2.6":82            suiteList.append(unittest.TestLoader().loadTestsFromTestCase(TFLayerTest))83    if found_pytorch:84        suiteList.append(unittest.TestLoader().loadTestsFromTestCase(TorchLayerTest))85        suiteList.append(unittest.TestLoader().loadTestsFromTestCase(FeatureModelsTestRunner))86        suiteList.append(unittest.TestLoader().loadTestsFromTestCase(FunctionTestRunner))87        suiteList.append(unittest.TestLoader().loadTestsFromName('test_mobilenet_v2', ModelTest))88        suiteList.append(unittest.TestLoader().loadTestsFromName('test_mobilenet_v3', ModelTest))89        suiteList.append(unittest.TestLoader().loadTestsFromName('test_efficientnet_b0', ModelTest))90        suiteList.append(unittest.TestLoader().loadTestsFromName('test_resnet18', ModelTest))91        suiteList.append(unittest.TestLoader().loadTestsFromName('test_shufflenet_v2_x1_0', ModelTest))92        suiteList.append(unittest.TestLoader().loadTestsFromTestCase(TestPytorchTPModel))93    # ----------------   Join them together and run them94    comboSuite = unittest.TestSuite(suiteList)...test_main.py
Source:test_main.py  
1# Copyright (c) Microsoft Corporation. All rights reserved.2# Licensed under the MIT License.3import sys4import random5import unittest6if __name__ == '__main__':7    sys.path.append(sys.argv[4])8    sys.path.append(sys.argv[5])9    import function_tests10    loader = unittest.TestLoader()11    test_classes = [function_tests.HttpJsonPayloadTests, function_tests.HttpProtobufPayloadTests, function_tests.HttpEndpointTests, function_tests.GRPCTests]12    test_suites = []13    for tests in test_classes:14        tests.server_app_path = sys.argv[1]15        tests.model_path = sys.argv[2]16        tests.test_data_path = sys.argv[3]17        tests.server_port = random.randint(30000, 50000)18        test_suites.append(loader.loadTestsFromTestCase(tests))19    suites = unittest.TestSuite(test_suites)20    runner = unittest.TextTestRunner(verbosity=2)21    results = runner.run(suites)22    23    if results.wasSuccessful():24        exit(0)25    else:26        exit(1)...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
