def window_size_should_be_equal_to_dimension_in_driver( self, driver: BrowserDriver, dimension: str, ): size = driver.get_window_size() Assert.should_be_equal_to_value(dimension, f"{size['width']}x{size['height']}")
def _read_metadata(self): """Read the transaction log from the cache directory. Reads the pickled log entries and re-creates the cache's current contents and use_order from the log. A version number is included, but currently we only assert that a the version number read is the same as the current version number. """ logpath = os.path.join(self.directory, 'LOG') try: log = open(logpath) except IOError: # now what happens if there is an error here? log = open(logpath, 'w') log.close() return for line in log.readlines(): try: kind = line[0:1] if kind == '2': # use update key = line[2:-1] self.use_order.remove(key) self.use_order.append(key) elif kind == '1': # delete key = line[2:-1] if self.items.has_key(key): self.size = self.size - self.items[key].size del self.items[key] del self.manager.items[key] self.use_order.remove(key) Assert(not key in self.use_order) elif kind == '0': # add newentry = DiskCacheEntry(self) newentry.parse(line[2:-1]) if not self.items.has_key(newentry.key): self.use_order.append(newentry.key) newentry.cache = self self.items[newentry.key] = newentry self.manager.items[newentry.key] = newentry self.size = self.size + newentry.size elif kind == '3': # version (hopefully first) ver = line[2:-1] if ver not in self.log_ok_versions: ### clear out anything we might have read ### and bail. this is an old log file. if len(self.use_order) > 0: self.use_order = [] for key in self.items.keys(): del self.items[key] del self.manager.items[key] self.size = 0 return Assert(ver in self.log_ok_versions) except IndexError: # ignore this line pass
def open(self): Assert(self.state == WAIT) resturl, method, params, data = self.args if data: Assert(method == "POST") else: Assert(method in ("GET", "POST")) if type(resturl) == type(()): host, selector = resturl # For proxy interface else: host, selector = splithost(resturl) if not host: raise IOError, "no host specified in URL" i = string.find(host, '@') if i >= 0: user_passwd, host = host[:i], host[i + 1:] else: user_passwd = None if user_passwd: import base64 auth = string.strip(base64.encodestring(user_passwd)) else: auth = None self.h = MyHTTP(host) self.h.putrequest(method, selector) self.h.putheader('User-agent', GRAILVERSION) if auth: self.h.putheader('Authorization', 'Basic %s' % auth) if not params.has_key('host'): self.h.putheader('Host', host) if not params.has_key('accept-encoding'): encodings = Reader.get_content_encodings() if encodings: encodings.sort() self.h.putheader('Accept-Encoding', string.join(encodings, ", ")) for key, value in params.items(): if key[:1] != '.': self.h.putheader(key, value) self.h.putheader('Accept', '*/*') self.h.endheaders() if data: self.h.send(data) self.readahead = "" self.state = META self.line1seen = 0 if self.reader_callback: self.reader_callback()
def getdata(self, maxbytes): Assert(self.stage == DATA) data = self.item.getdata(self.offset, maxbytes) self.offset = self.offset + len(data) if not data: self.close() return data
def getdata(self, maxbytes): Assert(self.state == nullAPI.DATA) split_pos = min(maxbytes, len(self.__data)) data = self.__data[:split_pos] self.__data = self.__data[split_pos:] if not data: self.state = nullAPI.DONE return data
def getmeta(self): Assert(self.state == META) self.state = DATA headers = {} headers['content-type'] = self.ctype headers['content-length'] = "%u" % len(self.data) self.lines = [] # Only used of self.isdir return 200, "OK", headers
def pollmeta(self, timeout=0): Assert(self.state == META) sock = self.h._conn.sock try: if not select.select([sock], [], [], timeout)[0]: return "waiting for server response", 0 except select.error, msg: raise IOError, msg, sys.exc_traceback
def decref(self): Assert(self.refcnt > 0) self.refcnt = self.refcnt - 1 self.cache_update() if self.refcnt == 0: if self.stage == DONE: self.finish() else: self.abort()
def getmeta(self): Assert(self.state == nullAPI.META) self.state = nullAPI.DATA headers = { "content-type": self.__ctype, "content-length": ` len(self.__data) `, } if self.__data: return 200, "Ready", headers return 204, "No content", headers
def getdata(self, maxbytes): Assert(self.state == DATA) if self.readahead: data = self.readahead[:maxbytes] self.readahead = self.readahead[maxbytes:] return data try: data = self.h._conn.sock.recv(maxbytes) except socket.error, msg: raise IOError, msg, sys.exc_traceback
def getmeta(self): Assert(self.state == META) if not self.readahead: x, y = self.pollmeta(None) while not y: x, y = self.pollmeta(None) file = StringIO.StringIO(self.readahead) errcode, errmsg, headers = self.h.getreply(file) self.state = DATA self.readahead = file.read() return errcode, errmsg, headers
def getdata(self, offset, maxbytes): Assert(offset >= 0) Assert(maxbytes > 0) while self.stage == DATA and offset >= self.datalen: buf = self.api.getdata(maxbytes) if not buf: self.finish() self.complete = 1 else: l = len(buf) if l > maxbytes: # we got more than we wanted, # so split into two strings (avoid search next time) self.data.append(buf[:maxbytes]) self.datamap[offset] = len(self.data) - 1 self.data.append(buf[maxbytes:]) self.datamap[offset + maxbytes] = len(self.data) - 1 else: self.data.append(buf) self.datamap[offset] = len(self.data) - 1 self.datalen = self.datalen + l try: # the common case chunk = self.data[self.datamap[offset]] if len(chunk) > maxbytes: return chunk[0:maxbytes] else: return chunk except KeyError: if self.stage == META: self.meta = self.api.getmeta() self.stage = DATA elif self.complete == 1 and offset >= self.datalen: return '' chunk_key, delta = self._getdata_search_string_list(offset) chunk = self.data[self.datamap[chunk_key]] return chunk[delta:]
def getdata(self, maxbytes): if self.state == EOF: self.state = DONE return "" Assert(self.state == DATA) data = self.sock.recv(maxbytes) if self.debuglevel > 4: print "*data*", `data` if not data: self.state = DONE if self.isdir: self.addlistingdata(data) data = self.getlistingdata() if self.state == DONE and data: self.state = EOF # Allow one more call return data
def getmeta(self): Assert(self.state == META) self.state = DATA headers = {} if self.isdir: if self.url and self.url[-1:] != '/': self.url = self.url + '/' self.content_type = 'text/html' self.content_encoding = None if self.content_type: headers['content-type'] = self.content_type if self.content_encoding: headers['content-encoding'] = self.content_encoding if self.content_length: headers['content-length'] = `self.content_length` self.lines = [] # Only used of self.isdir return 200, "OK", headers
def __init__(self): gloVar.pathPyFramework = "C:\Python3\Scripts\MJN" gloVar.pathPyFrameworkLog = gloVar.pathPyFramework + "\log.txt" gloVar.pathPyFrameworkCapture = "C:\Python3\Scripts\MJN\Screenshot\\" gloVar.pathPyFrameworkCommon = gloVar.pathPyFramework + "\Common" gloVar.pathPyFrameworkPageObject = gloVar.pathPyFramework + "\PageObject" gloVar.pathPyFrameworkTC = gloVar.pathPyFramework + "\TestCase" gloVar.TCResultFile = TXT(gloVar().getLogTCResult()) gloVar.TCResultFile.write(gloVar.caseName + ":" + "FAIL") gloVar.log = log.Logger(gloVar.caseName, gloVar.pathPyFrameworkLog) self.driver = webdriver.Chrome() gloVar.testResult = True gloVar.driver = self.driver gloVar.currentWindowHandle = self.driver.current_window_handle self.Excel = Excel() self.Assert = Assert() self.PageObject = PageObject() self.Shortcut = Shortcut() self.dataJSON = JSON( "C:\\Python3\\Scripts\\MJN\\TestData\\TestData.json") gloVar.PageObject = self.PageObject
def getdata(self, maxbytes): Assert(self.state == DATA) data = self.fp.read(maxbytes) if not data: self.state = DONE return data
def polldata(self): Assert(self.state == DATA) return "Ready", 1
def getmeta(self): Assert(self.state == META) self.state = DATA if self.redirect: return 301, "Redirect to absolute pathname", {"location": self.url} return 200, "OK", self.headers
def pollmeta(self): Assert(self.state == META) return "Ready", 1
def get(self, key): """Update and log use_order.""" Assert(self.items.has_key(key)) self.use_order.remove(key) self.use_order.append(key) self.log_use_order(key)
def __init__(self, url, method, params): Assert(method == 'GET') netloc, path = splithost(url) if not netloc: raise IOError, ('ftp error', 'no host given') host, port = splitport(netloc) user, host = splituser(host) if user: user, passwd = splitpasswd(user) else: passwd = None host = socket.gethostbyname(host) if port: try: port = string.atoi(port) except string.atoi_error: raise IOError, ('ftp error', 'bad port') else: port = ftplib.FTP_PORT path, attrs = splitattr(path) self.url = "ftp://%s%s" % (netloc, path) dirs = string.splitfields(path, '/') dirs, file = dirs[:-1], dirs[-1] self.content_length = None if not file: self.content_type, self.content_encoding = None, None type = 'd' else: self.content_type, self.content_encoding = app.guess_type(file) if self.content_encoding: type = 'i' elif self.content_type and self.content_type[:5] == 'text/': type = 'a' elif file[-1] == '/': type = 'd' else: type = 'i' if dirs and not dirs[0]: dirs = dirs[1:] key = (user, host, port, string.joinfields(dirs, '/')) self.debuglevel = None try: if not ftpcache.has_key(key): ftpcache[key] = [] for attr in attrs: [attr, value] = map(string.lower, splitvalue(attr)) if attr == 'type' and value in ('a', 'i', 'd'): type = value elif attr == 'debug': try: self.debuglevel = string.atoi(value) except string.atoi_error: pass candidates = ftpcache[key] for cand in candidates: if not cand.busy(): break else: cand = ftpwrapper(user, passwd, host, port, dirs, self.debuglevel) candidates.append(cand) # XXX Ought to clean the cache every once in a while self.cand = cand self.sock, self.isdir = cand.retrfile(file, type) self.content_length = cand.content_length except ftplib.all_errors, msg: raise IOError, ('ftp error', msg)
def expire(self, key): """Should not be used.""" Assert('night' == 'day') Assert(self.items.has_key(key)) self.items[key].evict()
def polldata(self): Assert(self.state in (EOF, DATA)) return "Ready", 1
def commands_in_driver_should_complete_successfully( self, driver: ShellDriver, ): Assert.Eq(0, driver.last_status)
def getdata(self, maxbytes): Assert(self.state == DATA) self.state = DONE return ""
def getmeta(self): Assert(self.state == META) self.state = DATA return 204, "No content", {}
def exit_status_in_driver_should_be_value( self, driver: ShellDriver, value: str, ): Assert.Eq(value, driver.scenario_output)
def polldata(self): Assert(self.state == DATA) if self.readahead: return "processing readahead data", 1 return ("waiting for data", len(select.select([self], [], [], 0)[0]))
def value_should_be_in_output_of_driver( self, driver: ShellDriver, value: str, ): Assert.In(value, driver.scenario_output)
def the_output_in_driver_should_be( self, driver: ShellDriver, value: str, ): Assert.In(value, driver.scenario_output)