http://www.slideshare.net/pvergain/multiprocessing-with-python-presentation
A video talk about the Python Global Interpreter Lock
http://blip.tv/file/2232410
Multiprocessing with python
View more presentations from Patrick Vergain
celeryctl inspect enable_events celeryev
{'date_field__range': (datetime.datetime.combine(date, datetime.time.min), datetime.datetime.combine(date, datetime.time.max))} `myapp_mytable`.`date` BETWEEN 2011-05-25 00:00:00 and 2011-05-25 23:59:59)'
unittest.py: sys.exit(not result.wasSuccessful()) ...where wasSuccessful() corresponds to this line: def wasSuccessful(self): "Tells whether or not this result was a success" return len(self.failures) == len(self.errors) == 0
""" _environments = [ # Firefox runs faster than IE7, so check first even though our customers use the latter browser more. {'platform' : "WINDOWS", 'browserName' : "firefox", 'version' : "3.6" }, {'platform' : "WINDOWS", 'browserName' : "iexplore", 'version' : "7" }, ] def run_suite(self, suite, **kwargs): r = None for env in _environments: print "Running %s" % env # We need Django nose to run XML coverage outputs on Hudson. For multiple browser support, we need # to change the --xunit-file parameter. if hasattr(settings, 'NOSE_ARGS'): nose_utils.swap_nose_args(suite, env) selenium_cfg.current_env = env test = super(SeleniumTestSuiteRunner, self).run_suite(suite, **kwargs) if not r: r = test else: r.failures.append(test.failures) r.errors.append(test.errors)If we try to use the code above as the test-runner, Hudson always will trigger a build failure. Why? Well it turns out whate need to make sure is that we use extend() instead of append(). If we use append(), we appending multiple lists within a list (i.e.):
>>> a = [] >>> a.append([]) >>> a [[]] >>> a.append([]) >>> a [[], []]
52 52 if not r: 53 53 r = test 54 54 else: 55 r.failures.append(test.failures) 56 r.errors.append(test.errors) 55 r.failures.extend(test.failures) 56 r.errors.extend(test.errors) 57 57
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile profile = FirefoxProfile(profile_directory="/home/myuserid/.mozilla") profile.update_preferences() # increases the num of simultaneous connections among other things from selenium.webdriver.common.desired_capabilities import DesiredCapabilities from selenium.webdriver.firefox.firefox_profile import FirefoxProfile profile = FirefoxProfile(profile_directory="/home/myuserid/.mozilla") selenium_browser = webdriver.Remote(desired_capabilities=DesiredCapabilities.FIREFOX, command_executor=http://anotherhost.com:4444/wd/hub', browser_profile=profile)
def wait_for_condition(self, js_cmd): # Selenium 2 no longer has a wait_for_condition, so we have to create our own polling routine. for i in xrange(30): ret = self.selenium.execute_script(js_cmd) if ret is True: return True time.sleep(.25) if ret is False: print "JavaScript command %s did not finish completing (ret_val=%s)" % (js_cmd, ret) raise ExceptionYou can then define a function to wait for jQuery Ajax events are completed by checking the jQuery.active flag. This flag is incremented whenever you invoke a $.ajax() call and decremented when you complete an Ajax call.
def js_wait(): wait_for_condition("return jQuery.active === 0")
sel = selenium sel.open("/app/") sel.click("css=#org_settings") sel.wait_for_page_to_load("30000") sel.type("news_title", "My News") sel.type("news_content", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sollicitudin faucibus magna quis varius. Aliquam erat volutpat. Morbi sit amet turpis at tellus consectetur aliquet. Tempus posuere interdum. Fusce eget orci risus.\n\nSed a diam ipsum. Duis faucibus blandit libero eget dictum. In non est justo, sit amet sollicitudin ipsum. Proin consequat, arcu sit amet venenatis dictum.") sel.click("news_publish_btn") sel.is_text_present("Reach")
sel = selenium sel.selenium.implicitly_wait(10) sel.get("/app/") sel.find_element_by_id("org_settings").click() sel.find_element_by_id("news_title").send_keys("My News") self.assertTrue(sel.find_element_by_xpath("//ul[@id='panels']/li[contains(@class, 'wrapper')]/H2[text()='Engagement']"))
selenium_browser = webdriver.Remote(desired_capabilities=current_env,command_executor="http://myhost:80/wd/hub"
selenium.execute_script('window.resizeTo(1600,768)' selenium_browser.execute_script('$("#djDebug, #djShowToolBar, #djDebugToolbarHandle").hide();')
<input>
or <textarea>
object, if it has the text selection at the time. If so, you can get more detail by using the element's selectionStart
and selectionEnd
properties. Other times the focused element might be a <select>
element (menu) or an <input>
element, of type
button, checkbox or radio.window.getSelection()
for that. <body>
. var curElement = document.activeElement;
2011-03-21T07:28:03Do the python bindings have webdriverbackedselenium? 2011-03-21T07:28:15 um kinda 2011-03-21T07:28:19 lol 2011-03-21T07:28:24 kinda is the right answer 2011-03-21T07:28:32 It's got the hooks we need to start adding pieces
2011-03-21T07:30:58Unfortunately 2.0b2 doesn't have the webdriverbackedselenium 2011-03-21T07:31:32 * AutomatedTester didnt realise its been deleted 2011-03-21T07:31:41 It was a mitake 2011-03-21T07:31:43 mistake
sel.click("//input[@myattr=%s]" % (id_selected)) sel.click("//input[@myAttr=%s]" % (id_selected))
telnet on.fb.me 80 Trying 168.143.174.97... Connected to cname.bit.ly. Escape character is '^]'. GET /[your shortened link here] HTTP/1.1 Host: on.fb.me HTTP/1.1 301 Moved Server: nginx
>>> import urllib2 >>> urllib2.urlopen('http://on.fb.me/[your shortened link here>'] Traceback (most recent call last): result = func(*args) File "/usr/lib/python2.6/urllib2.py", line 516, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 404: Not Found
class CustomHTTPRedirectHandler(urllib2.HTTPRedirectHandler): # If a redirect happens within a 301, we deal with it here. def redirect_request(self, req, fp, code, msg, hdrs, newurl): parsed_url = urlparse.urlparse(newurl) # See http://code.google.com/web/ajaxcrawling/docs/getting-started.html # # Strip out the hash fragment, since fragments are never (by # specification) sent to the server. If you do, a 404 error can occur. # urllib2.urlopen() also will die a glorius death if you try, so you must # remove it. See http://stackoverflow.com/questions/3798422 for more info. # Facebook does not really conform to the Google standard, so we can't # send the fragment as _escaped_fragment_=key=value. # Strip out the URL fragment and reconstruct everything if a hash tag exists. if newurl.find('#') != -1: newurl = "%s://%s%s" % (parsed_url.scheme, parsed_url.netloc, parsed_url.path) return urllib2.HTTPRedirectHandler.redirect_request(self, req, fp, code, msg, hdrs, newurl)
opener = urllib2.build_opener(CustomHTTPRedirectHandler()) req = urllib2.Request('http://on.fb.me[your shortened link here]') print opener.open(req).read()
‘M-x delete-trailing-whitespace’
(GnuEmacs version 21 or later). You can put this in ‘before-save-hook’
to ensure that your files have no trailing whitespace:(add-hook 'before-save-hook 'delete-trailing-whitespace)