小编ale*_*cxe的帖子

使用Protractor检查浏览器控制台中是否有错误

我正在使用Protractor来测试AngularJS

我想检查一下,在测试结束时没有发生未捕获的异常,并打印到浏览器控制台.

有一个简单的方法吗?

javascript testing selenium angularjs protractor

9
推荐指数
2
解决办法
5049
查看次数

如何在请求中获取页面标题

在请求中获取页面标题的最简单方法是什么?

r = requests.get('http://www.imdb.com/title/tt0108778/')
# ? r.title
Friends (TV Series 1994–2004) - IMDb
Run Code Online (Sandbox Code Playgroud)

html python html-parsing

9
推荐指数
4
解决办法
2万
查看次数

Django中的详细弃用警告

从django 1.3升级到django 1.5后,我开始DeprecationWarnings在测试运行期间看到这些:

path_to_virtualenv/lib/python2.6/site-packages/django/http/request.py:193:DeprecationWarning:HttpRequest.raw_post_data已被弃用.请改用HttpRequest.body.

我在项目里面搜索过raw_post_data,一无所获.所以它没有直接用在项目中.然后,我手动完成INSTALLED_APPS,发现该raven模块仍然使用raw_post_data,这是原因,但..

是否可以DeprecationWarning在测试运行期间查看原因?如何让这些警告更加冗长?

python django warnings django-1.5 deprecation-warning

8
推荐指数
2
解决办法
3818
查看次数

在PyPy下使用__slots__

我有这个简单的代码帮助我测量类的__slots__执行方式(从这里开始):

import timeit

def test_slots():
    class Obj(object):
        __slots__ = ('i', 'l')

        def __init__(self, i):
            self.i = i
            self.l = []

    for i in xrange(1000):
        Obj(i)

print timeit.Timer('test_slots()', 'from __main__ import test_slots').timeit(10000)
Run Code Online (Sandbox Code Playgroud)

如果我通过python2.7运行它 - 我会在6秒左右得到一些东西 - 好吧,它比没有插槽时更快(并且内存效率更高).

但是,如果我在PyPy下运行代码(使用2.2.1 - 64位用于Mac OS/X),它开始使用100%CPU并且"从不"返回(等待几分钟 - 没有结果).

到底是怎么回事?我应该__slots__在PyPy下使用吗?

如果我传递不同的数字,会发生什么timeit():

timeit(10) - 0.067s
timeit(100) - 0.5s
timeit(1000) - 19.5s
timeit(10000) - ? (probably more than a Game of Thrones episode)
Run Code Online (Sandbox Code Playgroud)

提前致谢.


请注意,如果我使用namedtuples,则会观察到相同的行为:

import collections
import timeit …
Run Code Online (Sandbox Code Playgroud)

python performance pypy slots

8
推荐指数
2
解决办法
868
查看次数

点正则表达式搜索

我需要找到PyPI匹配特定正则表达式的所有包:

^django-.*?admin.*$
Run Code Online (Sandbox Code Playgroud)

基本上,包的名字应该与启动django-,并有admin后话.例如,以下包应该匹配:

django-redis-admin
django-admin-ckeditor 
django-admintools-bootstrap
Run Code Online (Sandbox Code Playgroud)

我能做到pip search django-,但是有很多我不感兴趣的软件包.

是否pip提供了一种通过正则表达式查找包的方法?或者,我应该只是管的结果django-,以grep过滤掉无关的包?

此外,可能是一个的"交集" pip search django-,并pip search admin有助于太.

python regex packages pip

8
推荐指数
1
解决办法
2291
查看次数

Python unittest忽略了numpy

我正在使用unittest编写python测试并从命令行运行测试

 nosetests --with-coverage -x
Run Code Online (Sandbox Code Playgroud)

当我在我的一个测试中包含numpy时,它也试图测试numpy包.示例输出:

...
Name                            Stmts   Miss  Cover   Missing
-------------------------------------------------------------
CLOCK                              39     33    15%   3, 7-13, 17, 20-25, 28-47
LFU                                42      1    98%   52
LRU                                95      9    91%   12, 64, 68, 101, 115-118, 131
LRU10                              54      1    98%   68
LRU3                               54      1    98%   68
argparse                         1177   1177     0%   3-2361
cache                              86     33    62%   36-47, 86-89, 95-116
common                             87     54    38%   17, 20, 23, 28, 31-32, 35-36, 39, 42, 46, 48, 50, 52, 54, 57-64, 67-68, 72-89, 95-96, 102-107, …
Run Code Online (Sandbox Code Playgroud)

python unit-testing numpy nosetests python-unittest

8
推荐指数
1
解决办法
1008
查看次数

如何在Protractor中配置firefox二进制位置?

我使用Chrome成功运行了Protractor测试,使用我的Protractor配置中的以下部分指定了我的chrome二进制文件的路径:

capabilities: {
// You can use other browsers
// like firefox, phantoms, safari, IE
'browserName': 'chrome',
"chromeOptions": {
  binary: 'C:/BuildSoftware/Chrome/Application/chrome.exe',
}
Run Code Online (Sandbox Code Playgroud)

这有效.

我的Firefox也安装在非标准位置.

在量角器配置中是否有相同的方法为Firefox指定二进制文件?

testing firefox angularjs protractor

8
推荐指数
2
解决办法
9567
查看次数

如何从Scraped Links [Python]下载PDF?

我正在使用Python制作PDF Web Scraper.基本上,我正试图从我的一个课程中获取所有课程笔记,这些课程都是PDF格式的.我想输入一个网址,然后获取PDF并将其保存在笔记本电脑的目录中.我看了几个教程,但我不完全确定如何去做.StackOverflow上的所有问题似乎都没有帮助我.

这是我到目前为止:

import requests
from bs4 import BeautifulSoup
import shutil

bs = BeautifulSoup

url = input("Enter the URL you want to scrape from: ")
print("")

suffix = ".pdf"

link_list = []

def getPDFs():    
    # Gets URL from user to scrape
    response = requests.get(url, stream=True)
    soup = bs(response.text)

    #for link in soup.find_all('a'): # Finds all links
     #   if suffix in str(link): # If the link ends in .pdf
      #      link_list.append(link.get('href'))
    #print(link_list)

    with open('CS112.Lecture.09.pdf', 'wb') as out_file:
        shutil.copyfileobj(response.raw, out_file)
    del …
Run Code Online (Sandbox Code Playgroud)

python pdf beautifulsoup web-scraping python-requests

8
推荐指数
1
解决办法
4215
查看次数

混合datetime.strptime()参数

datetime.strptime()使用以下方法混合格式字符串和日期字符串参数是一个常见的错误:

datetime.strptime("%B %d, %Y", "January 8, 2014")
Run Code Online (Sandbox Code Playgroud)

而不是相反:

datetime.strptime("January 8, 2014", "%B %d, %Y")
Run Code Online (Sandbox Code Playgroud)

当然,它会在运行时失败:

>>> datetime.strptime("%B %d, %Y", "January 8, 2014")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_strptime.py", line 325, in _strptime
    (data_string, format))
ValueError: time data '%B %d, %Y' does not match format 'January 8, 2014'
Run Code Online (Sandbox Code Playgroud)

但是,即使在实际运行代码之前,是否有可能静态地捕获此问题?是东西pylint还是flake8可以帮忙?


我已经尝试过PyCharm代码检查,但两个代码段都没有发出任何警告.可能,因为两个参数都具有相同的类型 - 它们都是字符串,这使得问题更加困难.我们必须实际分析字符串是否是日期时间格式字符串.此外,语言注入 PyCharm/IDEA功能看起来相关.

python datetime pylint static-code-analysis pycharm

8
推荐指数
1
解决办法
983
查看次数

在Protractor中直接在JavaScript中定位元素

在其中一个测试中,我需要滚动到一个元素的视图,这可以通过使用Protractor定位的元素参数化脚本的scrollIntoView()方法来完成:

var elm = element(by.id("myid"));
browser.executeScript("arguments[0].scrollIntoView();", elm.getWebElement());
Run Code Online (Sandbox Code Playgroud)

但是,我们也可以通过getElementById()以下方式直接找到元素:

browser.executeScript("document.getElementById('myid').scrollIntoView();");
Run Code Online (Sandbox Code Playgroud)

这两种方法有什么区别?

scrollIntoView()被选择用于仅样品的目的.脚本中的逻辑可能更复杂.

javascript testing selenium selenium-webdriver protractor

8
推荐指数
1
解决办法
393
查看次数