How to use file_size method in Airtest

Best Python code snippet using Airtest Github


Full Screen

1from .utils import HTTPException2class RangeParser(object):3 def __call__(self, header, file_size):4 prefix = "bytes="5 if not header.startswith(prefix):6 raise HTTPException(416, message="Unrecognised range type %s" % (header,))7 parts = header[len(prefix):].split(",")8 ranges = []9 for item in parts:10 components = item.split("-")11 if len(components) != 2:12 raise HTTPException(416, "Bad range specifier %s" % (item))13 data = []14 for component in components:15 if component == "":16 data.append(None)17 else:18 try:19 data.append(int(component))20 except ValueError:21 raise HTTPException(416, "Bad range specifier %s" % (item))22 try:23 ranges.append(Range(data[0], data[1], file_size))24 except ValueError:25 raise HTTPException(416, "Bad range specifier %s" % (item))26 return self.coalesce_ranges(ranges, file_size)27 def coalesce_ranges(self, ranges, file_size):28 rv = []29 target = None30 for current in reversed(sorted(ranges)):31 if target is None:32 target = current33 else:34 new = target.coalesce(current)35 target = new[0]36 if len(new) > 1:37 rv.append(new[1])38 rv.append(target)39 return rv[::-1]40class Range(object):41 def __init__(self, lower, upper, file_size):42 self.file_size = file_size43 self.lower, self.upper = self._abs(lower, upper)44 if self.lower >= self.upper or self.lower >= self.file_size:45 raise ValueError46 def __repr__(self):47 return "<Range %s-%s>" % (self.lower, self.upper)48 def __lt__(self, other):49 return self.lower < other.lower50 def __gt__(self, other):51 return self.lower > other.lower52 def __eq__(self, other):53 return self.lower == other.lower and self.upper == other.upper54 def _abs(self, lower, upper):55 if lower is None and upper is None:56 lower, upper = 0, self.file_size57 elif lower is None:58 lower, upper = max(0, self.file_size - upper), self.file_size59 elif upper is None:60 lower, upper = lower, self.file_size61 else:62 lower, upper = lower, min(self.file_size, upper + 1)63 return lower, upper64 def coalesce(self, other):65 assert self.file_size == other.file_size66 if (self.upper < other.lower or self.lower > other.upper):67 return sorted([self, other])68 else:69 return [Range(min(self.lower, other.lower),70 max(self.upper, other.upper) - 1,71 self.file_size)]72 def header_value(self):...

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:


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

Run Airtest 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?