How to use list_extensions method in tempest

Best Python code snippet using tempest_python

Joselle_Abagat_X442.3_Final_Project.py

Source:Joselle_Abagat_X442.3_Final_Project.py Github

copy

Full Screen

1'''2Created on Mar 30, 20123@author: joselle44'''5import re6import os7class Extensions(object):8 '''9 classdocs10 '''11 def __init__(self, directory_string):12 '''13 Constructor14 '''15 self.list_extensions = self.mapFileSizesToExtension(directory_string)16 def mapFileSizesToExtension(self, directory_string):17 extension_dictionary = {}18 19 for root, dirs, files in os.walk(directory_string):20 for eachfile in files:21 22 #need to account for filenames like: "blah 2.12.2012.txt"23 getExtension = re.compile(r'[^.]*.(\w*)$',re.I)24 extension = getExtension.findall(eachfile)25 extension = extension[0]26 27 try:28 file_size = int(os.path.getsize(os.path.join(root, eachfile)))29 except WindowsError:30 file_size = 031 32 if not extension in extension_dictionary:33 extension_dictionary[extension] = [file_size]34 else:35 extension_dictionary[extension].append(file_size)36 37 return extension_dictionary38 39 def getNumberOfFiles(self, file_extension): 40 try:41 return len(self.list_extensions[file_extension])42 except KeyError:43 print("The extension is not a key in the dictionary")44 45 def getMinFileSize(self, file_extension):46 try:47 return min(self.list_extensions[file_extension])48 except TypeError:49 pass50 except KeyError:51 print("The extension is not a key in the dictionary")52 53 def getMaxFileSize(self, file_extension):54 try:55 return max(self.list_extensions[file_extension])56 except TypeError:57 pass58 except KeyError:59 print("The extension is not a key in the dictionary")60 61 def getAveFileSize(self, file_extension):62 try:63 return sum(self.list_extensions[file_extension])/self.getNumberOfFiles(file_extension)64 except TypeError:65 pass66 except KeyError:67 print("The extension is not a key in the dictionary")68 except ZeroDivisionError:69 print("There are 0 files with that extension")70 71 def RunReport(self):72 for each_key in self.list_extensions:73 s = "Extension: '" + str(each_key) + "'" + \74 "\n\tNumber of Files: " + str(self.getNumberOfFiles(each_key)) + \75 "\n\tMax file size: " + str(self.getMaxFileSize(each_key)) + " bytes" + \76 "\n\tMin file size: " + str(self.getMinFileSize(each_key)) + " bytes" + \77 "\n\tAverage file size: " + str(self.getAveFileSize(each_key)) + " bytes"78 print(s)79 return s80filename = "..\\..\\..\\"81print(os.path.abspath(filename))82ext = Extensions(filename)...

Full Screen

Full Screen

test_extension_commands.py

Source:test_extension_commands.py Github

copy

Full Screen

...24 self.patcher.stop()25 shutil.rmtree(self.ext_dir, ignore_errors=True)26 def test_no_extensions_dir(self):27 shutil.rmtree(self.ext_dir)28 actual = list_extensions()29 self.assertEqual(len(actual), 0)30 def test_no_extensions_in_dir(self):31 actual = list_extensions()32 self.assertEqual(len(actual), 0)33 def test_add_list_show_remove_extension(self):34 add_extension(MY_EXT_SOURCE)35 actual = list_extensions()36 self.assertEqual(len(actual), 1)37 ext = show_extension(MY_EXT_NAME)38 self.assertEqual(ext[OUT_KEY_NAME], MY_EXT_NAME)39 remove_extension(MY_EXT_NAME)40 num_exts = len(list_extensions())41 self.assertEqual(num_exts, 0)42 def test_add_extension_twice(self):43 add_extension(MY_EXT_SOURCE)44 num_exts = len(list_extensions())45 self.assertEqual(num_exts, 1)46 with self.assertRaises(CLIError):47 add_extension(MY_EXT_SOURCE)48 def test_add_extension_invalid(self):49 with self.assertRaises(ValueError):50 add_extension(MY_BAD_EXT_SOURCE)51 actual = list_extensions()52 self.assertEqual(len(actual), 0)53 def test_add_extension_invalid_whl_name(self):54 with self.assertRaises(CLIError):55 add_extension(os.path.join('invalid', 'ext', 'path', 'file.whl'))56 actual = list_extensions()57 self.assertEqual(len(actual), 0)58 def test_add_extension_valid_whl_name_filenotfound(self):59 with self.assertRaises(CLIError):60 add_extension(_get_test_data_file('mywheel-0.0.3+dev-py2.py3-none-any.whl'))61 actual = list_extensions()62 self.assertEqual(len(actual), 0)63if __name__ == '__main__':...

Full Screen

Full Screen

test_list_extensions.py

Source:test_list_extensions.py Github

copy

Full Screen

...7 list_extensions),8]9cs = fakes.FakeClient(extensions=extensions)10class ListExtensionsTests(utils.TestCase):11 def test_list_extensions(self):12 all_exts = cs.list_extensions.show_all()13 cs.assert_called('GET', '/extensions')14 self.assertTrue(len(all_exts) > 0)15 for r in all_exts:...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful