How to use _human_readable_size method in fMBT

Best Python code snippet using fMBT_python

test_glance_replicator.py

Source:test_glance_replicator.py Github

copy

Full Screen

...311 def test_replication_size_with_bad_args(self):312 args = ['aaa']313 command = glance_replicator.replication_size314 self.assertTrue(check_bad_args(command, args))315 def test_human_readable_size(self):316 _human_readable_size = glance_replicator._human_readable_size317 self.assertEqual('0.0 B', _human_readable_size(0))318 self.assertEqual('1.0 B', _human_readable_size(1))319 self.assertEqual('512.0 B', _human_readable_size(512))320 self.assertEqual('1.0 KiB', _human_readable_size(1024))321 self.assertEqual('2.0 KiB', _human_readable_size(2048))322 self.assertEqual('8.0 KiB', _human_readable_size(8192))323 self.assertEqual('64.0 KiB', _human_readable_size(65536))324 self.assertEqual('93.3 KiB', _human_readable_size(95536))325 self.assertEqual('117.7 MiB', _human_readable_size(123456789))326 self.assertEqual('36.3 GiB', _human_readable_size(39022543360))327 def test_replication_dump(self):328 tempdir = self.useFixture(fixtures.TempDir()).path329 options = moves.UserDict()330 options.chunksize = 4096331 options.mastertoken = 'mastertoken'332 options.metaonly = False333 args = ['localhost:9292', tempdir]334 orig_img_service = glance_replicator.get_subject_service335 self.addCleanup(setattr, glance_replicator,336 'get_subject_service', orig_img_service)337 glance_replicator.get_subject_service = get_subject_service338 glance_replicator.replication_dump(options, args)339 for active in ['5dcddce0-cba5-4f18-9cf4-9853c7b207a6',340 '37ff82db-afca-48c7-ae0b-ddc7cf83e3db']:...

Full Screen

Full Screen

torrent.py

Source:torrent.py Github

copy

Full Screen

...12 self.params = {13 'save_path': torrents_path,14 'storage_mode': lt.storage_mode_t(2)15 }16 def _human_readable_size(self, size):17 prefixes = ('B', 'kB', 'MB', 'GB', 'TB')18 count = 019 while size > 1024:20 size /= 102421 count+=122 return f'{size:.2f} {prefixes[count]}'23 def _new_download_info(self, name, link, downloaded, size):24 with open(downloads_data, 'r+') as file:25 downloads_list = json.loads(file.read())26 for download in downloads_list: 27 if download['magnet_link'] == link: return28 json_data = {"name": name, "magnet_link": link, 'total_downloaded': downloaded, 'size': size}29 downloads_list.append(json_data)30 file.seek(0)31 json.dump(downloads_list, file)32 file.truncate()33 def _edit_download_info(self, link, info, value):34 with open(downloads_data, 'r+') as file:35 downloads_list = json.loads(file.read())36 index = tuple(index for index, x in enumerate(downloads_list) if x['magnet_link'] == link)[0]37 downloads_list[index][info] = value38 file.seek(0)39 json.dump(downloads_list, file)40 file.truncate()41 def _downloading_status(self, s):42 state_str = ['queued', 'checking', 'downloading metadata', \43 'downloading', 'finished', 'seeding', 'allocating']44 line_1 = f'\r{self._human_readable_size(s.total_done)} of {self._human_readable_size(s.total_wanted)} ({(s.progress*100):.2f}%) '45 line_2 = (f'Downloading from {s.num_peers} peers - ('46 f'{self._human_readable_size(s.download_rate)}/s▾ '47 f'{self._human_readable_size(s.upload_rate)}/s▴) '48 f'{state_str[s.state]} ')49 print(line_1)50 print(line_2, end='')51 print('\033[1A', end='\x1b[2K')52 def _wait_torrent(self, handle, magnet_link):53 print('Downloading Metadata...')54 wait_time = 055 while (not handle.has_metadata()): 56 print(f'\r{"."*wait_time}', end='')57 wait_time+=158 if wait_time > 60: raise Exception('Timeout')59 time.sleep(1) 60 print ('Got Metadata, Starting Torrent Download...')61 print("Starting", handle.name())...

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 fMBT 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