Best Python code snippet using green
test_versionType.py
Source:test_versionType.py  
1# -*- coding: utf-8 -*-2# Copyright (c) 2009-2012, Erkan Ozgur Yilmaz3# 4# This module is part of oyProjectManager and is released under the BSD 25# License: http://www.opensource.org/licenses/BSD-2-Clause6import os7import shutil8import tempfile9import unittest10from sqlalchemy.exc import IntegrityError11from oyProjectManager import conf, db12from oyProjectManager.models.project import Project13from oyProjectManager.models.version import VersionType14class VersionTypeTester(unittest.TestCase):15    """tests the VersionType class16    """17    18    def setUp(self):19        """setup the test settings with environment variables20        """21        # -----------------------------------------------------------------22        # start of the setUp23        conf.database_url = "sqlite://"24        25        # create the environment variable and point it to a temp directory26        self.temp_config_folder = tempfile.mkdtemp()27        self.temp_projects_folder = tempfile.mkdtemp()28        29        os.environ["OYPROJECTMANAGER_PATH"] = self.temp_config_folder30        os.environ[conf.repository_env_key] = self.temp_projects_folder31        32        self.test_project = Project("TEST_PROJ1")33        self.test_project.create()34        self.test_project.save()35        36        self.kwargs = {37#            "project": self.test_project,38            "name":"Test VType",39            "code":"TVT",40            "path":"{{project.full_path}}/Sequences/{{sequence.code}}/SHOTS/{{version.base_name}}/{{type.code}}",41            "filename":"{{version.base_name}}_{{version.take_name}}_{{type.code}}_v{{'%03d'|format(version.version_number)}}_{{version.created_by.initials}}",42            "environments":["MAYA","HOUDINI"],43            "output_path":"SHOTS/{{version.base_name}}/{{type.code}}/OUTPUT/{{version.take_name}}",44            "extra_folders":"""{{version.path}}/exports45            {{version.path}}/cache46            """,47            "type_for": "Shot"48        }49        50        self.test_versionType = VersionType(**self.kwargs)51        self.test_versionType.save()52        53        self._name_test_values = [54            ("base name", "Base_Name"),55            ("123123 base_name", "Base_Name"),56            ("123432!+!'^+Base_NAme323^+'^%&+%&324", "Base_NAme323324"),57            ("    ---base 9s_name", "Base_9s_Name"),58            ("    ---base 9s-name", "Base_9s_Name"),59            (" multiple     spaces are    converted to under     scores",60             "Multiple_Spaces_Are_Converted_To_Under_Scores"),61            ("camelCase", "CamelCase"),62            ("CamelCase", "CamelCase"),63            ("_Project_Setup_", "Project_Setup"),64            ("_PROJECT_SETUP_", "PROJECT_SETUP"),65            ("FUL_3D", "FUL_3D"),66            ("BaseName", "BaseName"),67            ("baseName", "BaseName"),68            (" baseName", "BaseName"),69            (" base name", "Base_Name"),70            (" 12base name", "Base_Name"),71            (" 12 base name", "Base_Name"),72            (" 12 base name 13", "Base_Name_13"),73            (">£#>$#£½$ 12 base £#$£#$£½¾{½{ name 13", "Base_Name_13"),74            ("_base_name_", "Base_Name"),75        ]76    77    def tearDown(self):78        """cleanup the test79        """80        # set the db.session to None81        db.session = None82        83        # delete the temp folder84        shutil.rmtree(self.temp_config_folder)85        shutil.rmtree(self.temp_projects_folder)86    87    def test_name_argument_is_None(self):88        """testing if a TypeError will be raised when the name argument is89        None90        """91        self.kwargs["name"] = None92        self.assertRaises(TypeError, VersionType, **self.kwargs)93    94    def test_name_attribute_is_None(self):95        """testing if a TypeError will be raised when the name attribute is96        set to None97        """98        self.assertRaises(TypeError, setattr, self.test_versionType, "name",99                          None)100    101    def test_name_argument_is_not_a_string(self):102        """testing if a TypeError will be raised when the name argument is not103        a string or unicode instance104        """105        self.kwargs["name"] = 123106        self.assertRaises(TypeError, VersionType, **self.kwargs)107    108    def test_name_attribute_is_not_a_string(self):109        """testing if a TypeError will be raised when the name argument is not110        a string or unicode instance111        """112        self.assertRaises(TypeError, setattr, self.test_versionType, "name", 8)113    114    def test_name_argument_is_working_properly(self):115        """testing if the name argument is working properly and sets the name116        attribute correctly117        """118        self.assertEqual(self.kwargs["name"], self.test_versionType.name)119    120    def test_name_attribute_is_working_properly(self):121        """testing if the name attribute is working properly122        """123        test_value = "New Name"124        self.test_versionType.name = test_value125        self.assertEqual(test_value, self.test_versionType.name)126    127    def test_name_attribute_is_not_unique(self):128        """testing if an IntegrityError error will be raised when the name129        argument is not unique130        """131        # creating a new VersionType should raise the ?? error132        new_vtype = VersionType(**self.kwargs)133        self.assertRaises(IntegrityError, new_vtype.save)134    135    def test_code_argument_is_skipped(self):136        """testing if a TypeError will be raised when the code argument is137        skipped138        """139        self.kwargs.pop("code")140        self.assertRaises(TypeError, VersionType, **self.kwargs)141    142    def test_code_argument_is_None(self):143        """testing if a TypeError will be raised when the code argument is144        None145        """146        self.kwargs["code"] = None147        self.assertRaises(TypeError, VersionType, **self.kwargs)148    149    def test_code_attribute_is_None(self):150        """testing if a TypeError will be raised when the code attribute is151        set to None152        """153        self.assertRaises(TypeError, setattr, self.test_versionType, "code",154                          None)155    156    def test_code_argument_is_not_a_string(self):157        """testing if a TypeError will be raised when the code argument is not158        a string or unicode instance159        """160        self.kwargs["code"] = 123161        self.assertRaises(TypeError, VersionType, **self.kwargs)162    163    def test_code_attribute_is_not_a_string(self):164        """testing if a TypeError will be raised when the code argument is not165        a string or unicode instance166        """167        self.assertRaises(TypeError, setattr, self.test_versionType, "code", 8)168    169    def test_code_argument_is_working_properly(self):170        """testing if the code argument is working properly and sets the code171        attribute correctly172        """173        self.assertEqual(self.kwargs["code"], self.test_versionType.code)174    175    def test_code_attribute_is_working_properly(self):176        """testing if the code attribute is working properly177        """178        test_value = "New Name"179        self.test_versionType.code = test_value180        self.assertEqual(test_value, self.test_versionType.code)181    182    def test_code_attribute_is_not_unique(self):183        """testing if an IntegrityError error will be raised when the code184        argument is not unique185        """186        # creating a new VersionType should raise the IntegrityError187        self.kwargs["name"] = "A Different Name"188        new_vtype = VersionType(**self.kwargs)189        self.assertRaises(IntegrityError, new_vtype.save)190    191    def test_filename_argument_is_skipped(self):192        """testing if a TypeError will be raised when the filename argument193        is skipped194        """195        self.kwargs.pop("filename")196        self.assertRaises(TypeError, VersionType, **self.kwargs)197    198    def test_filename_argument_is_empty_string(self):199        """testing if a ValueError will be raised when the filename argument200        is an empty string201        """202        self.kwargs["filename"] = ""203        self.assertRaises(ValueError, VersionType, **self.kwargs)204    205    def test_filename_attribute_is_empty_string(self):206        """testing if a ValueError will be raised when the filename attribute207        is set to an empty string208        """209        self.assertRaises(ValueError, setattr, self.test_versionType,210                          "filename", "")211    212    def test_filename_argument_is_not_a_string(self):213        """testing if a TypeError will be raised when the filename argument is214        not a string instance215        """216        self.kwargs["filename"] = 13245217        self.assertRaises(TypeError, VersionType, **self.kwargs)218    219    def test_filename_attribute_is_not_a_string(self):220        """testing if a TypeError will be raised when the filename attribute is221        not a string instance222        """223        self.assertRaises(TypeError, setattr, self.test_versionType,224                          "filename", 23412)225    226    def test_filename_argument_is_working_properly(self):227        """testing if the filename attribute is initialized correctly with the228        same value of the filename argument229        """230        self.assertEqual(self.test_versionType.filename,231                         self.kwargs["filename"])232    233    def test_filename_attribute_is_working_properly(self):234        """testing if the filename attribute is working properly235        """236        test_value = "test_filename"237        self.test_versionType.filename = test_value238        self.assertEqual(self.test_versionType.filename, test_value)239    240    def test_path_argument_is_skipped(self):241        """testing if a TypeError will be raised when the path argument242        is skipped243        """244        self.kwargs.pop("path")245        self.assertRaises(TypeError, VersionType, **self.kwargs)246    247    def test_path_argument_is_empty_string(self):248        """testing if a ValueError will be raised when the path argument249        is an empty string250        """251        self.kwargs["path"] = ""252        self.assertRaises(ValueError, VersionType, **self.kwargs)253    254    def test_path_attribute_is_empty_string(self):255        """testing if a ValueError will be raised when the path attribute256        is set to an empty string257        """258        self.assertRaises(ValueError, setattr, self.test_versionType, "path",259                          "")260    261    def test_path_argument_is_not_a_string(self):262        """testing if a TypeError will be raised when the path argument is263        not a string instance264        """265        self.kwargs["path"] = 13245266        self.assertRaises(TypeError, VersionType, **self.kwargs)267    268    def test_path_attribute_is_not_a_string(self):269        """testing if a TypeError will be raised when the path attribute is270        not a string instance271        """272        self.assertRaises(TypeError, setattr, self.test_versionType,273                          "path", 23412)274    275    def test_path_argument_is_working_properly(self):276        """testing if the path attribute is initialized correctly with the277        same value of the path argument278        """279        self.assertEqual(self.test_versionType.path,280                         self.kwargs["path"])281    282    def test_path_attribute_is_working_properly(self):283        """testing if the path attribute is working properly284        """285        test_value = "test_path"286        self.test_versionType.path = test_value287        self.assertEqual(self.test_versionType.path, test_value)288    289    def test_output_path_argument_is_skipped(self):290        """testing if a TypeError will be raised when the output_path291        argument is skipped292        """293        self.kwargs.pop("output_path")294        self.assertRaises(TypeError, VersionType, **self.kwargs)295    296    def test_output_path_argument_is_empty_string(self):297        """testing if a ValueError will be raised when the output_path298        argument is an empty string299        """300        self.kwargs["output_path"] = ""301        self.assertRaises(ValueError, VersionType, **self.kwargs)302    303    def test_output_path_attribute_is_empty_string(self):304        """testing if a ValueError will be raised when the output_path305        attribute is set to an empty string306        """307        self.assertRaises(ValueError, setattr, self.test_versionType,308                          "output_path", "")309    310    def test_output_path_argument_is_not_a_string(self):311        """testing if a TypeError will be raised when the output_path argument312        is not a string instance313        """314        self.kwargs["output_path"] = 13245315        self.assertRaises(TypeError, VersionType, **self.kwargs)316    317    def test_output_path_attribute_is_not_a_string(self):318        """testing if a TypeError will be raised when the output_path attribute319        is not a string instance320        """321        self.assertRaises(TypeError, setattr, self.test_versionType,322                          "output_path", 23412)323    324    def test_output_path_argument_is_working_properly(self):325        """testing if the output_path attribute is initialized correctly with326        the same value of the output_path argument327        """328        self.assertEqual(self.test_versionType.output_path,329                         self.kwargs["output_path"])330    331    def test_output_path_attribute_is_working_properly(self):332        """testing if the output_path attribute is working properly333        """334        test_value = "test_output_path"335        self.test_versionType.output_path = test_value336        self.assertEqual(self.test_versionType.output_path, test_value)337    338    def test_extra_folders_argument_is_skipped(self):339        """testing if the extra_folders argument is skipped the extra_folders340        attribute will be an empty string341        """342        self.kwargs.pop("extra_folders")343        new_version_type = VersionType(**self.kwargs)344        self.assertEqual(new_version_type.extra_folders, "")345    346    def test_extra_folders_argument_is_None(self):347        """testing if the extra_folders attribute is going to be an empty348        string when the extra folders argument is given as None349        """350        self.kwargs["extra_folders"] = None351        new_version_type = VersionType(**self.kwargs)352        self.assertEqual(new_version_type.extra_folders, "")353    354    def test_extra_folders_attribute_is_None(self):355        """testing if the extra_folders attribute will be an empty list when it356        is set to None357        """358        self.test_versionType.extra_folders = None359        self.assertEqual(self.test_versionType.extra_folders, "")360    361    def test_extra_folders_argument_is_not_a_string_instance(self):362        """testing if a TypeError will be raised when the extra_folders363        argument is not a string or unicode instance364        """365        self.kwargs["extra_folders"] = 123366        self.assertRaises(TypeError, VersionType, **self.kwargs)367    368    def test_extra_folders_attribute_is_not_a_string_instance(self):369        """testing if a TypeError will be raised when the extra_folders370        attribute is set to something other than a string or unicode instance371        """372        self.assertRaises(TypeError, setattr, self.test_versionType,373                          "extra_folders", 23423)374    375    def test_extra_folders_argument_is_working_properly(self):376        """testing if the extra_folders attribute will be set to the same value377        with the extra_folders argument while initialization378        """379        self.assertEqual(self.test_versionType.extra_folders,380                         self.kwargs["extra_folders"])381    382    def test_extra_folders_attribute_is_working_properly(self):383        """testing if the extra_folders attribute is working properly384        """385        test_value = "extra_folders"386        self.test_versionType.extra_folders = test_value387        self.assertEqual(self.test_versionType.extra_folders, test_value)388    389    def test_environments_argument_is_skipped(self):390        """testing if a TypeError will be raised when the environments391        argument is skipped392        """393        self.kwargs.pop("environments")394        self.assertRaises(TypeError, VersionType, **self.kwargs)395    396    def test_environments_argument_is_None(self):397        """testing if a TypeError will be raised when the environments398        argument is None399        """400        self.kwargs["environments"] = None401        self.assertRaises(TypeError, VersionType, **self.kwargs)402    403    def test_environments_attribute_is_None(self):404        """testing if a TypeError will be raised when the environments405        attribute is set to None406        """407        self.assertRaises(TypeError, setattr, self.test_versionType,408                          "environments", None)409    410    def test_environments_argument_is_not_a_list(self):411        """testing if a TypeError will be raised when the environments argument412        is not a list instance413        """414        self.kwargs["environments"] = 12354415        self.assertRaises(TypeError, VersionType, **self.kwargs)416    417    def test_environments_attribute_is_not_a_list(self):418        """testing if a TypeError will be raised when the environments419        attribute is set to something other than a list420        """421        self.assertRaises(TypeError, setattr, self.test_versionType,422                          "environments", 123)423    424    def test_environments_argument_is_not_a_list_of_strings(self):425        """testing if a TypeError will be raised when the environments argument426        is not a list of strings427        """428        self.kwargs["environments"] = [123, "MAYA"]429        self.assertRaises(TypeError, VersionType, **self.kwargs)430    431    def test_environments_attribute_is_not_a_list_of_strings(self):432        """testing if a TypeError will be raised when the environments433        attribute is not a list of strings434        """435        self.assertRaises(TypeError, setattr, self.test_versionType,436                          "environments", [123, "MAYA"])437    438    def test_environments_argument_works_properly(self):439        """testing if the environments attribute will be initialized correctly440        with the environments argument441        """442        test_value = ["MAYA", "HOUDINI"]443        self.kwargs["environments"] = test_value444        new_vtype = VersionType(**self.kwargs)445        446        for env in test_value:447            self.assertTrue(env in new_vtype.environments)448    449    def test_environments_attribute_works_properly(self):450        """testing if the environments attribute is working properly451        """452        test_value = ["MAYA", "HOUDINI", "NUKE", "3DEQUALIZER"]453        self.test_versionType.environments = test_value454        455        for env in test_value:456            self.assertTrue(env in self.test_versionType.environments)457    458    def test_type_for_argument_is_skipped(self):459        """testing if a TypeError will be raised when the type_for argument is460        skipped461        """462        self.kwargs.pop("type_for")463        self.assertRaises(TypeError, VersionType, **self.kwargs)464    465    def test_type_for_argument_is_None(self):466        """testing if a TypeError will be raised when the type_for argument467        is None468        """469        self.kwargs["type_for"] = None470        self.assertRaises(TypeError, VersionType, **self.kwargs)471    472    def test_type_for_argument_is_not_a_string_or_integer(self):473        """testing if a TypeError will be raised when the type_for argument is474        not a string or unicode or an integer475        """476        self.kwargs["type_for"] = [12]477        self.assertRaises(TypeError, VersionType, **self.kwargs)478    479    def test_type_for_argument_is_working_properly(self):480        """testing if the type_for argument is working properly481        """482        self.kwargs["name"] = "Test Animation"483        self.kwargs["code"] = "TA"484        self.kwargs["type_for"] = "Asset"485        new_vtype = VersionType(**self.kwargs)486        new_vtype.save()487        self.assertEqual(new_vtype.type_for, "Asset")488    489    def test_type_for_attribute_is_read_only(self):490        """testing if type_for attribute is read-only491        """492        self.assertRaises(AttributeError, setattr, self.test_versionType,493                          "type_for", "Asset")494    495    def test_save_method_saves_the_version_type_to_the_database(self):496        """testing if the save method saves the current VersionType to the497        database498        """499        self.kwargs["name"] = "Test Animation"500        self.kwargs["code"] = "TA"501        new_vtype = VersionType(**self.kwargs)502        new_vtype.save()503        504        code = new_vtype.code505        environments = new_vtype.environments506        filename = new_vtype.filename507        name = new_vtype.name508        output_path = new_vtype.output_path509        path = new_vtype.path510        type_for = new_vtype.type_for511        512#        del new_vtype513        514        new_vtypeDB = VersionType.query().\515            filter_by(name=self.kwargs["name"]).first()516        517        self.assertEqual(code, new_vtypeDB.code)518        self.assertEqual(filename, new_vtypeDB.filename)519        self.assertEqual(name, new_vtypeDB.name)520        self.assertEqual(output_path, new_vtypeDB.output_path)521        self.assertEqual(path, new_vtypeDB.path)522        self.assertEqual(type_for, new_vtypeDB.type_for)523        self.assertEqual(environments, new_vtypeDB.environments)524    525    def test__eq__(self):526        """testing the equality operator527        """528        529        verst1 = VersionType(530            name="Test Type",531            code="TT",532            path="path",533            filename="filename",534            output_path="output_path",535            environments=["MAYA", "NUKE"],536            type_for="Asset"537        )538        539        verst2 = VersionType(540            name="Test Type",541            code="TT",542            path="path",543            filename="filename",544            output_path="output_path",545            environments=["MAYA", "NUKE"],546            type_for="Asset"547        )548        549        verst3 = VersionType(550            name="Test Type 2",551            code="TT",552            path="path",553            filename="filename",554            output_path="output_path",555            environments=["MAYA", "NUKE"],556            type_for="Asset"557        )558        559        verst4 = VersionType(560            name="Test Type 3",561            code="TT3",562            path="path",563            filename="filename",564            output_path="output_path",565            environments=["MAYA", "NUKE"],566            type_for="Asset"567        )568        569        self.assertTrue(verst1==verst2)570        self.assertFalse(verst1==verst3)571        self.assertFalse(verst3==verst4)572    573    def test__ne__(self):574        """testing the equality operator575        """576        577        verst1 = VersionType(578            name="Test Type",579            code="TT",580            path="path",581            filename="filename",582            output_path="output_path",583            environments=["MAYA", "NUKE"],584            type_for="Asset"585        )586        587        verst2 = VersionType(588            name="Test Type",589            code="TT",590            path="path",591            filename="filename",592            output_path="output_path",593            environments=["MAYA", "NUKE"],594            type_for="Asset"595        )596        597        verst3 = VersionType(598            name="Test Type 2",599            code="TT",600            path="path",601            filename="filename",602            output_path="output_path",603            environments=["MAYA", "NUKE"],604            type_for="Asset"605        )606        607        verst4 = VersionType(608            name="Test Type 3",609            code="TT3",610            path="path",611            filename="filename",612            output_path="output_path",613            environments=["MAYA", "NUKE"],614            type_for="Asset"615        )616        617        self.assertFalse(verst1!=verst2)618        self.assertTrue(verst1!=verst3)...test_version.py
Source:test_version.py  
2import unittest3from green.version import __version__, pretty_version4import green.version5class TestVersion(unittest.TestCase):6    def test_versionType(self):7        """8        __version__ is a unicode string9        """10        self.assertEqual(type(__version__), type(""))11    def test_versionSet(self):12        """13        __version__ is not blank14        """15        self.assertTrue(len(__version__) > 0)16    def test_pretty_version(self):17        """18        pretty_version() has the content we expect19        """20        pv = pretty_version()...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!!
