Best Python code snippet using robotframework
releasebuild.py
Source:releasebuild.py  
...98    scriptpath = os.path.realpath(__file__)99    projectpath = os.path.dirname(os.path.dirname(scriptpath))100    addonspath = os.path.join(projectpath, "addons")101    missionspath = os.path.join(projectpath, "missions")102    workdrivepath = os.path.normpath("P:")103    temppath = os.path.join(projectpath, "temp")104    if not os.path.exists(os.path.normpath(projectpath + "/privatekeys/")):105        os.makedirs(os.path.normpath(projectpath + "/privatekeys/"))106    if not os.path.exists(os.path.normpath(projectpath + "/release/@dorb/keys")):107        os.makedirs(os.path.normpath(projectpath + "/release/@dorb/keys"))108    if os.path.exists(os.path.normpath(projectpath + "/release/@dorb/addons")):109        shutil.rmtree(os.path.normpath(projectpath + "/release/@dorb/addons"), ignore_errors=True)110    os.makedirs(os.path.normpath(projectpath + "/release/@dorb/addons"))111    if os.path.exists(os.path.normpath(projectpath + "/release/@dorb/mpmissions")):112        shutil.rmtree(os.path.normpath(projectpath + "/release/@dorb/mpmissions"),\113            ignore_errors=True)114    os.makedirs(os.path.normpath(projectpath + "/release/@dorb/mpmissions"))115    made = 0116    failed = 0117    if platform.system() == "Windows":118        path_armake = os.path.normpath(projectpath + "/tools/armake_w64.exe")119    else:120        path_armake = "armake"121        workdrivepath = os.path.normpath("/mnt/p/")122    major, minor, patch, build = get_version(os.path.normpath(addonspath \123        + "/main/script_version.hpp"), version_increments)124    print("  Version: {}.{}.{}.{}".format(major, minor, patch, build), "\n")125    if not os.path.exists(os.path.normpath(projectpath + \126        "/privatekeys/kerberos_{}.{}.biprivatekey".format(major, minor))):127        print("  Creating the new keys kerberos_{}.{} \n".format(major, minor))128        command = path_armake + " keygen -f " + os.path.normpath(projectpath + \129            "/privatekeys/kerberos_{}.{}".format(major, minor))130        subprocess.check_output(command, stderr=subprocess.STDOUT, shell=True)131    shutil.copy(os.path.normpath(projectpath + \132        "/privatekeys/kerberos_{}.{}.bikey".format(major, minor)), \133        os.path.normpath(projectpath + \134        "/release/@dorb/keys/kerberos_{}.{}.bikey".format(major, minor)))135    print("  Creating the servermod")136    releasepath = os.path.normpath(projectpath + "/release/@dorb/addons")137    for file in os.listdir(addonspath):138        path = os.path.join(addonspath, file)139        if not os.path.isdir(path):140            continue141        if file[0] == ".":142            continue143        print("  Making {}{} ...".format(PREFIX, file))144        try:145            command = path_armake + " build -i " + workdrivepath + \146                " -w unquoted-string" + " -w redefinition-wo-undef" + \147                " -f " + os.path.normpath(addonspath + "/" + file) + " " + \148                os.path.normpath(releasepath + "/" + PREFIX + file + ".pbo")149            subprocess.check_output(command, stderr=subprocess.STDOUT, shell=True)150            command = path_armake + " sign -f " + os.path.normpath(projectpath + \151                "/privatekeys/kerberos_{}.{}.biprivatekey ".format(major, minor)) + \152                os.path.normpath(releasepath + "/" + PREFIX + file + ".pbo")153            subprocess.check_output(command, stderr=subprocess.STDOUT, shell=True)154        except:155            failed += 1156            print("    Failed to make {}{}.".format(PREFIX, file))157        else:158            made += 1159            print("    Successfully made {}{}.".format(PREFIX, file))160    print("\n  Creating the mission files")161    if os.path.exists(temppath):162        shutil.rmtree(temppath, ignore_errors=True)163    shutil.copy(os.path.normpath(addonspath + "/main/script_version.hpp"), \164        os.path.normpath(missionspath + "/" + MAINMISSION + "/main/script_version.hpp"))165    releasepath = os.path.normpath(projectpath + "/release/@dorb/mpmissions")166    if not os.path.exists(releasepath):167        os.makedirs(releasepath)168    for file in os.listdir(missionspath):169        path = os.path.join(missionspath, file)170        if not os.path.isdir(path):171            continue172        if file[0] == ".":173            continue174        print("  Making {} ...".format(file))175        try:176            if file == MAINMISSION:177                command = path_armake + " build -p -i " + workdrivepath + \178                " -w unquoted-string" + " -w redefinition-wo-undef" + \179                " -f " + os.path.normpath(missionspath + "/" + file) + " " + \180                os.path.normpath(releasepath + "/" + file + ".pbo")181                subprocess.check_output(command, stderr=subprocess.STDOUT, shell=True)182            else:183                os.makedirs(temppath)184                newdir = os.path.normpath(temppath + "/" + file)185                shutil.copytree(os.path.normpath(missionspath + "/" + MAINMISSION), newdir)186                copy_tree(os.path.normpath(missionspath + "/" + file), newdir)187                command = path_armake + " build -p -i " + workdrivepath + \188                " -w unquoted-string" + " -w redefinition-wo-undef" + \189                " -f " + newdir + " " + \190                os.path.normpath(releasepath + "/" + file + ".pbo")191                subprocess.check_output(command, stderr=subprocess.STDOUT, shell=True)192                shutil.rmtree(temppath, ignore_errors=True)193        except:194            failed += 1195            print("    Failed to make {}.".format(file))196        else:197            made += 1198            print("    Successfully made {}.".format(file))199    releasepath = os.path.normpath(projectpath + "/release/@dorb")200    shutil.copy(os.path.normpath(projectpath + "/LICENSE"), \201        os.path.normpath(releasepath + "/LICENSE"))202    shutil.copy(os.path.normpath(projectpath + "/README.md"), \203        os.path.normpath(releasepath + "/README.md"))204    releasename = "{}_{}.{}.{}.{}".format(MAINMISSION.rsplit(".", 1)[0], major, minor, patch, build)205    os.chdir(os.path.normpath(projectpath))206    shutil.make_archive("{}".format(releasename), "zip", \207       os.path.normpath(projectpath + "/release"))208    print("\n  Done. \n")209    print("  Made {}, failed to make {}.\n".format(made, failed))210if __name__ == "__main__":211    STARTTIME = timeit.default_timer()212    main(sys.argv)213    HOURS, MINUTES, SECONDS = fract_sec(timeit.default_timer() - STARTTIME)214    print("\nTotal Program time elapsed: {0:2}h   {1:2}m   {2:4.5f}s".format(HOURS, \215        MINUTES, SECONDS))...test_ntpath.py
Source:test_ntpath.py  
...98        tester("ntpath.join('a', '', '', '', '')", 'a\\')99        tester("ntpath.join('a\\', '')", 'a\\')100        tester("ntpath.join('a\\', '', '', '', '')", 'a\\')101102    def test_normpath(self):103        tester("ntpath.normpath('A//////././//.//B')", r'A\B')104        tester("ntpath.normpath('A/./B')", r'A\B')105        tester("ntpath.normpath('A/foo/../B')", r'A\B')106        tester("ntpath.normpath('C:A//B')", r'C:A\B')107        tester("ntpath.normpath('D:A/./B')", r'D:A\B')108        tester("ntpath.normpath('e:A/foo/../B')", r'e:A\B')109110        tester("ntpath.normpath('C:///A//B')", r'C:\A\B')111        tester("ntpath.normpath('D:///A/./B')", r'D:\A\B')112        tester("ntpath.normpath('e:///A/foo/../B')", r'e:\A\B')113114        tester("ntpath.normpath('..')", r'..')115        tester("ntpath.normpath('.')", r'.')116        tester("ntpath.normpath('')", r'.')117        tester("ntpath.normpath('/')", '\\')118        tester("ntpath.normpath('c:/')", 'c:\\')119        tester("ntpath.normpath('/../.././..')", '\\')120        tester("ntpath.normpath('c:/../../..')", 'c:\\')121        tester("ntpath.normpath('../.././..')", r'..\..\..')122        tester("ntpath.normpath('K:../.././..')", r'K:..\..\..')123        tester("ntpath.normpath('C:////a/b')", r'C:\a\b')124        tester("ntpath.normpath('//machine/share//a/b')", r'\\machine\share\a\b')125126        # Issue 5827: Make sure normpath preserves unicode127        for path in (u'', u'.', u'/', u'\\', u'///foo/.//bar//'):128            self.assertTrue(isinstance(ntpath.normpath(path), unicode),129                            'normpath() returned str instead of unicode')130131        tester("ntpath.normpath('\\\\.\\NUL')", r'\\.\NUL')132        tester("ntpath.normpath('\\\\?\\D:/XY\\Z')", r'\\?\D:/XY\Z')133134    def test_expandvars(self):135        oldenv = os.environ.copy()136        try:137            os.environ.clear()138            os.environ["foo"] = "bar"139            os.environ["{foo"] = "baz1"140            os.environ["{foo}"] = "baz2"141            tester('ntpath.expandvars("foo")', "foo")142            tester('ntpath.expandvars("$foo bar")', "bar bar")143            tester('ntpath.expandvars("${foo}bar")', "barbar")144            tester('ntpath.expandvars("$[foo]bar")', "$[foo]bar")145            tester('ntpath.expandvars("$bar bar")', "$bar bar")146            tester('ntpath.expandvars("$?bar")', "$?bar")
...test_macpath.py
Source:test_macpath.py  
...99        self.assertEqual(ismount(b"a:b"), False)100        self.assertEqual(ismount(b"a:b:"), True)101        self.assertEqual(ismount(b""), False)102        self.assertEqual(ismount(b":"), False)103    def test_normpath(self):104        normpath = macpath.normpath105        self.assertEqual(normpath("a:b"), "a:b")106        self.assertEqual(normpath("a"), ":a")107        self.assertEqual(normpath("a:b::c"), "a:c")108        self.assertEqual(normpath("a:b:c:::d"), "a:d")109        self.assertRaises(macpath.norm_error, normpath, "a::b")110        self.assertRaises(macpath.norm_error, normpath, "a:b:::c")111        self.assertEqual(normpath(":"), ":")112        self.assertEqual(normpath("a:"), "a:")113        self.assertEqual(normpath("a:b:"), "a:b")114        self.assertEqual(normpath(b"a:b"), b"a:b")115        self.assertEqual(normpath(b"a"), b":a")116        self.assertEqual(normpath(b"a:b::c"), b"a:c")117        self.assertEqual(normpath(b"a:b:c:::d"), b"a:d")118        self.assertRaises(macpath.norm_error, normpath, b"a::b")119        self.assertRaises(macpath.norm_error, normpath, b"a:b:::c")120        self.assertEqual(normpath(b":"), b":")121        self.assertEqual(normpath(b"a:"), b"a:")122        self.assertEqual(normpath(b"a:b:"), b"a:b")123class MacCommonTest(test_genericpath.CommonTest, unittest.TestCase):124    pathmodule = macpath125    test_relpath_errors = None126if __name__ == "__main__":...test_path.py
Source:test_path.py  
...22        23        24    def test_normpath_abs(self):25        osdp_path = OsdpPath()26        self.assertEqual(osdp_path.normpath('c:/Windows'), 'c:\\Windows')27        self.assertEqual(osdp_path.normpath('c:/A/B/C\D\E'), 'c:\\A\\B\\C\\D\\E')28        self.assertEqual(osdp_path.normpath('c:/A/B/C\.\E'), 'c:\\A\\B\\C\\E')29        self.assertEqual(osdp_path.normpath('c:/A/B/C\..\E'), 'c:\\A\\B\\E')30        self.assertEqual(osdp_path.normpath('c:/A/B/C\..\..\..\E'), 'c:\\E')31        self.assertEqual(osdp_path.normpath('c:/A/B/C\..\.\..\E'), 'c:\\A\\E')32        self.assertEqual(osdp_path.normpath('c:/A/B/C\D\\E'), 'c:\\A\\B\\C\\D\\E')33        34    def test_normpath_windows_abs(self):35        osdp_path = OsdpPath()36        self.assertEqual(osdp_path.normpath_windows('c:/Windows'), 'c:\\Windows')37        self.assertEqual(osdp_path.normpath_windows('c:/A/B/C\D\E'), 'c:\\A\\B\\C\\D\\E')38        self.assertEqual(osdp_path.normpath_windows('c:/A/B/C\.\E'), 'c:\\A\\B\\C\\E')39        self.assertEqual(osdp_path.normpath_windows('c:/A/B/C\..\E'), 'c:\\A\\B\\E')40        self.assertEqual(osdp_path.normpath_windows('c:/A/B/C\..\..\..\E'), 'c:\\E')41        self.assertEqual(osdp_path.normpath_windows('c:/A/B/C\..\.\..\E'), 'c:\\A\\E')42        self.assertEqual(osdp_path.normpath_windows('c:/A/B/C\D\\E'), 'c:\\A\\B\\C\\D\\E')43    def test_normpath_windows_rel(self):44        osdp_path = OsdpPath()45        self.assertEqual(osdp_path.normpath_windows('A/B/C\D\\E'), 'A\\B\\C\\D\\E')46        self.assertEqual(osdp_path.normpath_windows('A/B/C/..\D\\E'), 'A\\B\\D\\E')47        self.assertEqual(osdp_path.normpath_windows('A/B/C/./..\D\\E'), 'A\\B\\D\\E')48        self.assertEqual(osdp_path.normpath_windows('A/B/C/../..\D\\E'), 'A\\D\\E')49        self.assertEqual(osdp_path.normpath_windows('A/B/C/../..\D\\E'), 'A\\D\\E')50        self.assertEqual(osdp_path.normpath_windows('A/B/C/../../..\D\\E'), 'D\\E')51        52        53    def test_normpath_rel(self):54        osdp_path = OsdpPath()55        self.assertEqual(osdp_path.normpath('A/B/C\D\\E'), 'A/B/C/D/E')56        self.assertEqual(osdp_path.normpath('A/B/C/..\D\\E'), 'A/B/D/E')57        self.assertEqual(osdp_path.normpath('A/B/C/./..\D\\E'), 'A/B/D/E')58        self.assertEqual(osdp_path.normpath('A/B/C/../..\D\\E'), 'A/D/E')59        self.assertEqual(osdp_path.normpath('A/B/C/../..\D\\E'), 'A/D/E')60        self.assertEqual(osdp_path.normpath('A/B/C/../../..\D\\E'), 'D/E')61    def test_normpath_windows_special_cases(self):62        osdp_path = OsdpPath()63        self.assertEqual(osdp_path.normpath_windows('c:/A/B/..\..\..\..\E'), 'c:\\E')64        self.assertEqual(osdp_path.normpath_windows('A/B/C/../../../..\D\\E'), 'D\\E')65    def test_is_abs(self):66        osdp_path = OsdpPath()67        self.assertEqual(osdp_path.is_abs('c:/File.txt'), True)68        self.assertEqual(osdp_path.is_abs('/home/File.txt'), True)69        70        71    def test_is_rel(self):72        osdp_path = OsdpPath()73        self.assertEqual(osdp_path.is_rel('File.txt'), True)74        self.assertEqual(osdp_path.is_rel('home/File.txt'), True)...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!!
