def test_eta_fail(): for etaobj in (FailETA1(), FailETA2(), FailETA3()): with pytest.raises(ValueError): progress.ProgressBar(fmt=' ', etaobj=etaobj) with pytest.raises(TypeError): progress.ProgressBar(fmt='{minutes}', etaobj=9)
def download(URL,chp,q): browser.get(URL) if(q==0): time.sleep(10) my_path = '/home/piyush/Downloads/'+chp #change path here try: os.mkdir(my_path) except FileExistsError: x = input("Directory already exists! Press Y to overwrite files: ") if(x != 'Y'): sys.exit() page = browser.page_source soup = BeautifulSoup(page, features='lxml') image = [] for div in soup.find_all('div',attrs={'id':'divImage'}): for img in div.find_all('img'): image.append(img['src']) l=len(image) print("Downloading "+chp) progress.ProgressBar(0, l, prefix = 'Progress:', suffix = 'Complete', length = 50) for i in range(0,l): urllib.request.urlretrieve(image[i], os.path.join(my_path, str(i))) progress.ProgressBar( i, l, prefix = 'Progress', suffix = 'Complete', length = 50) print("File Downloaded at "+my_path)
def test_keyword_updates(): testbar = progress.ProgressBar('[{progress}]') l = list(range(3)) d = dict(a=1, b=3) testbar.show(*l, **d) testbar.autoupdate(10, *l, **d)
def extractAudio(self): # https://mkvtoolnix.download/doc/mkvextract.html # Assumes there is one audio track only, format is DTS and language is en toolfile = os.path.join(self.libexecfolder, 'mkvextract.exe') audiofile = '{}.dts'.format(os.path.splitext(self.mkvfilename)[0]) cmd = [ toolfile, self.mkvfilename, 'tracks', '{}:{}'.format(self.audio['id'] - 1, audiofile) ] process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True) bar = progress.ProgressBar( 'Extracting DTS: [{progress}] {percentage:.2f}%', width=50) bar.show() while True: output = process.stdout.readline() if output == '': break if output and output.startswith('Progress'): # print(output.strip()) r = re.match('Progress: (\d+)%', output) if r: perc = int(r.group(1)) bar.reset() bar.update(perc) bar.show() rc = process.poll() return rc '''
def test_percent_property(): testbar = progress.ProgressBar('[{progress}]') testbar.percent = 0.73408248 assert approx_equals(testbar.percent, 0.73408248) assert testbar.value == testbar.max * 0.73408248 assert testbar.min == 0 assert testbar.max == 100
def test_autoupdate(): testbar = progress.ProgressBar('[{progress}]') testbar.autoupdate(22) assert testbar.value == 22 assert testbar.percent == 0.22 assert testbar.min == 0 assert not testbar.done()
def test_reserved_keys_modification_fail(): testbar = progress.ProgressBar('[{progress}]') d = dict() # Fails because progress is a reserved key with pytest.raises(ValueError): d['progress'] = 'I am not allowed :(' testbar.autoupdate(5, **d)
def test_output_target_switch(): testbar = progress.ProgressBar('[{progress}]') testbar.target = sys.stdout assert testbar.target is sys.stdout with pytest.raises(ValueError): testbar.target = sys.stdin
def test_width_property(): testbar = progress.ProgressBar('[{progress}]') testbar.value = 75 assert testbar.value == 75 testbar.width = 30 assert testbar.width == 30 assert str(testbar) == '[' +\ (testbar.char * (int(testbar.width * 0.75) - 1)) + testbar.head +\ (testbar.fill * (int(testbar.width * 0.25) + 1)) + ']'
def test_reset(): testbar = progress.ProgressBar('[{progress}] {minutes}:{seconds}', etaobj=progress.eta.SimpleETA()) testbar.value = 50 testbar.percent == 50.0 testbar.reset() assert testbar.value == 0 assert testbar.percent == 0.0 assert not testbar.done() assert str(testbar) == '[' + testbar.head +\ (testbar.fill * (testbar.width - 1)) + '] 0:0' assert testbar.eta_object.eta == 0
def test_proper_init(): simple_eta = progress.eta.SimpleETA() testbar = progress.ProgressBar('[{progress}] {minutes}', etaobj=simple_eta) assert testbar.min == 0 assert testbar.max == 100 assert testbar.char == '=' assert testbar.head == '>' assert testbar.width == 20 assert len(testbar) == len('[' + (testbar.fill * testbar.width) + ' 0]') assert testbar._has_eta assert testbar._etaobj is simple_eta assert repr(testbar) == "ProgressBar(format='[{progress}] {minutes}', "\ "value=0)"
def test_min_max_value_properties(): testbar = progress.ProgressBar('[{progress}]') # Test setting the 'min' property testbar.min = -10 assert testbar.min == -10 testbar.max = 200 assert testbar.max == 200 testbar.value = 50 assert testbar.value == 50 assert approx_equals(testbar.percent, 0.2857142857142857) testbar.value = 95 assert testbar.value == 95 assert approx_equals(testbar.percent, 0.5)
def test_visual_changes(): testbar = progress.ProgressBar('[{progress}]') testbar.value = 0 testbar += 50 testbar.max = 200 assert testbar.max == 200 assert testbar.min == 0 testbar.head = '?' assert testbar.head == '?' testbar.char = '@' assert testbar.char == '@' testbar.fill = '_' assert testbar.fill == '_' assert str(testbar) == '[' +\ ('@' * (int(testbar.width * 0.25) - 1)) + '?' +\ ('_' * (int(testbar.width * 0.75))) + ']' assert testbar.target is sys.stderr
def test_formatting(): testbar = progress.ProgressBar('[{progress}]') assert type(testbar.format) is str testbar.format = "{percentage}%" assert testbar.format == "{percentage}%" # Test setting an ETA testbar.format = "{progress} {percentage}% {minutes}" assert testbar._has_eta # Fails due to 'progress' key being used twice with pytest.raises(ValueError): testbar.format = "{progress} {progress}" # Fails due to an empty format string with pytest.raises(ValueError): testbar.format = ""
def __init__(self, config, testsList): self.config = config self.testsList = testsList self.leakList = {} self.time = 0 self.timeout = False self.startTime = 0 self.resultSuccess = {} self.resultFailed = {} self.resultPlatformFailed = {} self.resultTimeout = {} self.resultCrashed = {} self.resultNew = {} self.pid = 0 self.count = 0 self.prog = progress.ProgressBar(0, len(testsList), 77, mode='fixed') self.webSocketServerRunning = False self.httpServerRunning = False self.webSocketServerPID = 0 self.httpServerPID = 0 os.environ["WEBKIT_TESTFONTS"] = os.path.abspath( self.config['source']) + "/WebKitTools/DumpRenderTree/bal/fonts/"
def test_property_fails(): testbar = progress.ProgressBar('[{progress}]') with pytest.raises(ValueError): testbar.char = '' with pytest.raises(ValueError): testbar.head = '' with pytest.raises(ValueError): testbar.fill = '' with pytest.raises(ValueError): testbar.char = '**' with pytest.raises(ValueError): testbar.head = ')))' with pytest.raises(ValueError): testbar.fill = 'urso' with pytest.raises(ValueError): testbar.width = 0 with pytest.raises(ValueError): testbar.width = -20 with pytest.raises(ValueError): testbar.min = 100 with pytest.raises(ValueError): testbar.min = 101 with pytest.raises(ValueError): testbar.max = 0 with pytest.raises(ValueError): testbar.max = -1
def test_progress_updates(): testbar = progress.ProgressBar('[{progress}]') # Attempt to update with a negative value with pytest.raises(ValueError): testbar.update(-10) with pytest.raises(ValueError): testbar += -20 # Test updates/states through properties testbar.value = 50 assert testbar.value == 50 assert testbar.percent == 0.5 assert testbar.max == 100 assert testbar.target is sys.stderr testbar.update(25) assert testbar.value == 75 assert testbar.percent == 0.75 testbar.value = 10 assert testbar.value == 10 assert testbar.percent == 0.10 testbar += 50 assert testbar.value == 60 assert testbar.percent == 0.60 testbar.value = -10 assert testbar.value == 0 assert testbar.percent == 0.0 testbar.value = 1000 assert testbar.value == 100 assert testbar.percent == 1.0 assert testbar.done()
def test_progressbar_argument_fail(): for kwargs in fail_kwargs: with pytest.raises(ValueError): progress.ProgressBar(**kwargs)
def test_default_eta(): testbar = progress.ProgressBar('[{progress}] {minutes}') assert testbar.eta == (0, 0, 0) assert isinstance(testbar.eta_object, progress.eta.SimpleETA)
pd.options.mode.chained_assignment = None # default='warn' # options = webdriver.ChromeOptions() # driver = webdriver.Chrome(options=options) driver = webdriver.Firefox(firefox_profile=profile) df = pd.read_csv('D:\\Users\\chenchr\\Desktop\\Stage\\aeo_stripe_modified.csv') time.sleep(2) ids = df['ID'] dates_de_reception = df['Date de reception'] offres = df['OFFRE'] liens = df['URL webapp'] col_nom = df["Nom sur site All Eat One"] liens = np.array(liens) noms = np.array(col_nom) bar = progress.ProgressBar( "[{progress}] {percentage:.2f}% ({minutes}:{seconds})", width=30) print('Connexion...') driver.get('https://alleatone.fr/admin/stores') driver.find_element_by_id('email').send_keys('*****@*****.**') driver.find_element_by_id('password').send_keys('Fyre@ll3@t12020') driver.find_element_by_id('password').send_keys(Keys.ENTER) wait(driver, 15).until(EC.presence_of_element_located((By.NAME, "user_role_id"))) driver.find_element_by_name('user_role_id') select = Select(driver.find_element_by_name('user_role_id')) select.select_by_visible_text('Fyre Admin') driver.find_element_by_id('password').send_keys(Keys.ENTER) wait(driver, 15).until( EC.presence_of_element_located( (By.XPATH,
from __future__ import print_function import time import random import progress import progress.eta def gen_random_update(mnsleep, mxsleep, mnvalue, mxvalue): """Generate a tuple of a random sleep period and update value.""" while True: yield random.uniform(mnsleep, mxsleep),\ random.randint(mnvalue, mxvalue) if __name__ == '__main__': bar = progress.ProgressBar(fmt='[{progress}] {nominator}KB, eta: ' '{minutes}:{seconds}', width=35, char='#', head='', etaobj=progress.eta.EMAETA()) while not bar.done(): bar.show() sleep, value = next(gen_random_update(0.05, 0.3, 1, 2)) time.sleep(sleep) bar += value bar.show() print("\nDone...")
# -*- coding: utf-8 -*- """Using ProgressBar to simulate downloading some files.""" from __future__ import print_function import time import random import progress def download_file(): """Simulate downloading a file.""" time.sleep(random.uniform(0.1, 0.2)) if __name__ == '__main__': bar = progress.ProgressBar("Downloading '{}'... ") for i in range(1, 4): bar.reset() bar.format = "Downloading '{}'... ".format('file' + str(i) + '.txt') +\ "{nominator}%" while not bar.done(): bar.autoupdate(random.randint(1, 5)) download_file() print() print("Done...")
def action_run(self): """ Runs a simulation and updates the explorer data. """ pbar = progress.ProgressBar(self, 'Creating simulation') QtWidgets.QApplication.processEvents( QtCore.QEventLoop.ExcludeUserInputEvents) try: pbar.show() QtWidgets.QApplication.processEvents( QtCore.QEventLoop.ExcludeUserInputEvents) # Create and run simulation out = self._sim_method() if type(out) == str: self._stream.write(out) return else: m, p, s = out QtWidgets.QApplication.processEvents( QtCore.QEventLoop.ExcludeUserInputEvents) pre = float(self._pre_field.text()) run = float(self._run_field.text()) if pre: s.pre(pre, progress=pbar.reporter()) d = s.run(run, progress=pbar.reporter()).npview() self._stream.write('Final state: \n' + m.format_state(s.state())) QtWidgets.QApplication.processEvents( QtCore.QEventLoop.ExcludeUserInputEvents) except myokit.SimulationCancelledError: return except myokit.MyokitError as e: self._stream.write(e.message) return except Exception as e: self._stream.write(str(e)) return finally: pbar.close() pbar.deleteLater() QtWidgets.QApplication.processEvents( QtCore.QEventLoop.ExcludeUserInputEvents) # Reset combo-box keys? reset_keys = True if self._keys: # Only reset keys if the old set differs from the new if self._keys == set(d.iterkeys()): reset_keys = False # Append or reset old data reset_plot = True if self._data: # Only reset if we can't append because keys have changed reset_plot = reset_keys # Perform plot/key reset (order is important!) if reset_plot: self._data = [] self._figure.clear() self._axes = None if reset_keys: x = self._select_x.currentText() y = self._select_y.currentText() self._select_x.clear() self._select_y.clear() for k in sorted(d.iterkeys()): self._select_x.addItem(k) self._select_y.addItem(k) self._keys = set(d.iterkeys()) # Attempt to keep current variables x = self._select_x.findText(x) if x < 0: # Guess: Use the time variable x = self._select_x.findText(m.time().qname()) self._select_x.setCurrentIndex(x) y = self._select_y.findText(y) if y < 0: # Guess: First log entry (first state) y = self._select_y.findText(d.iterkeys().next()) self._select_y.setCurrentIndex(y) # Add new data self._data.append(d) # Draw self.action_draw()
#!/usr/bin/env/python # -*- coding: utf-8 -*- """An example that mimicks the progress bar of wget.""" from __future__ import print_function import time import random import progress if __name__ == '__main__': fmt = '{percentage:.0f}% [{progress}] eta {minutes:.2f}m {seconds:.2f}s' bar = progress.ProgressBar(fmt, width=45, max=73945, etaobj=progress.eta.EMAETA()) while True: bar.show() time.sleep(random.randint(1, 2)) bar.update(random.randint(8245, 9245)) if bar.done(): bar.show() print() break