出于某种原因,该super()方法并不总是按预期运行,选择返回:
TypeError('super(type, obj): obj must be an instance or subtype of type)'
Run Code Online (Sandbox Code Playgroud)
我理解错误的含义.我不明白为什么它会出现错误.这是破解的代码片段.系统中的所有对象都是新样式对象.
真正有趣的是,这个错误并不总是出现.我不知道是什么导致了它.该super()在方法Retrieval中传递Retrieval类,然后本身作为一个对象,它是,据我所知,究竟如何super()是应该被调用.
有什么想法吗?
在文件DBConnection.py中:
class DBAdminConnection(object):
def __init__(self):
self.user = DBUserConnection().user
self.submissions = DBSubmissionConnection()
Run Code Online (Sandbox Code Playgroud)
在文件Retrieval.py中
class Retrieval(DBConnection.DBAdminConnection):
def __init__(self, username=None, password=None, unique_key=None):
super(Retrieval,self).__init__()
if username and password:
self.username = username
self.user.login(username,password, config.DATABASE)
if self.user.error:
raise UserLoginError(username)
self.unique_key = unique_key
Run Code Online (Sandbox Code Playgroud) 我正在使用crontab为我的minecraft服务器运行维护脚本.大多数情况下它工作正常,除非crontab尝试使用重启脚本.如果我手动运行重启脚本,则没有任何问题.因为我认为它与路径名称有关,所以我试图确保它总是从Minecraft目录中执行任何minecraft命令.所以我在pushd/popd中包含命令:
os.system("pushd /directory/path/here")
os.system("command to sent to minecraft")
os.system("popd")
Run Code Online (Sandbox Code Playgroud)
下面是一个互动会话,将我的世界排除在外.一个简单的"ls"测试.正如你所看到的,它根本没有运行来自pushd目录的os.system命令,而是来自/ etc /,这是我运行python的目录,以说明我的观点.Clearly pushd无法通过python运行所以我想知道我还能做到这一点.谢谢!
>>> def test():
... import os
... os.system("pushd /home/[path_goes_here]/minecraft")
... os.system("ls")
... os.system("popd")
...
>>> test()
~/minecraft /etc
DIR_COLORS cron.weekly gcrypt inputrc localtime mime.types ntp ppp rc3.d sasldb2 smrsh vsftpd.ftpusers
DIR_COLORS.xterm crontab gpm-root.conf iproute2 login.defs mke2fs.conf ntp.conf printcap rc4.d screenrc snmp vsftpd.tpsave
X11 csh.cshrc group issue logrotate.conf modprobe.d odbc.ini profile rc5.d scsi_id.config squirrelmail vz
adjtime csh.login group- issue.net logrotate.d motd odbcinst.ini profile.d rc6.d securetty ssh warnquota.conf
aliases …Run Code Online (Sandbox Code Playgroud) 我正在更新一个测试覆盖率很差的继承存储库。repo 本身是一个 pytest 插件。我已经将 repo 更改为与tox一起使用pytest-cov,并将“原始”测试转换pytester为在测试插件时按照 pytest 文档中的建议使用。
测试和 tox 构建等效果很好。但是,覆盖率报告了类定义、导入等的错误未命中。这是因为代码本身是作为 pytest 实例化的一部分导入的,并且在测试实际开始之前不会被“覆盖”。
我已经阅读了 pytest 文档、pytest-cov 和覆盖率文档以及 tox 文档,并尝试了几种配置,但都无济于事。我已经用尽了可能会导致我找到一个好的解决方案的谷歌关键字组合池。
pkg_root/
.tox/
py3/
lib/
python3.7/
site-pacakges/
plugin_module/
supporting_module.py
plugin.py
some_data.dat
plugin_module/
supporting_module.py
plugin.py
some_data.dat
tests/
conftest.py
test_my_plugin.py
tox.ini
setup.py
Run Code Online (Sandbox Code Playgroud)
一些带有评论的相关片段:
[pytest]
addopts = --cov={envsitepackagesdir}/plugin_module --cov-report=html
testpaths = tests
Run Code Online (Sandbox Code Playgroud)
这个配置给我一个错误,没有收集数据;在这种情况下不会创建 htmlcov。
如果我只是使用--cov,我会得到(预期的)非常嘈杂的覆盖范围,它显示了功能命中和未命中,但是上面报告了导入、类定义等的错误未命中。
pytest_plugins = ['pytester'] # Entire contents of file!
Run Code Online (Sandbox Code Playgroud)
def test_a_thing(testdir):
testdir.makepyfile(
"""
def test_that_fixture(my_fixture):
assert my_fixture.foo == …Run Code Online (Sandbox Code Playgroud) 在工作中,我很遗憾地被迫使用Windows.我对gVim提供的字体选择感到不满(阅读:愤怒),我想把它改成我在家里的开发电脑上使用的字体.
但是,当涉及到set guifont =选项的可用内容时,gVim的选项有限.即使我知道有问题的字体对于VIM是很好的,因为我在其他地方使用它,我不知道如何添加到可用字体列表,即使我已经在这台机器上安装它,我找不到这个信息随处可见
有没有人对此有任何见解?我真的不明白为什么我不能把guifont设置为任何等宽字体我该死的,而不是gVim认为最好的.
编辑:据我所知,这个问题的根本原因是安装了正确的 Perl 模块,但mysql.so加载了错误的文件。
my $dsn = "DBI:mysql:"
. "database=$db;"
. "host=$dbhost;"
. "mysql_ssl=$dbssl;"
. "mysql_skip_secure_auth=1;";
Run Code Online (Sandbox Code Playgroud)
我最近尝试升级我们的 DBD::mysql 版本,但一直遇到DBI connect('database=mydb;host=myhost','myuser',...) failed: Connection using old (pre-4.1.1)错误。
经过数小时的调试,并确定我们的整个系统无法正确选择不更新我们的 mysql 表的密码散列方法的正确选项,我发现使用DBD::Mysql 4.027您可以声明“mysql_skip_secure_auth”作为您的一部分域名
但是,这似乎不起作用。
如果我运行mysql -h $myhost -u $myuser -p --skip-secure-auth,我可以毫无意外地连接,但是尝试使用 DBI/DBD::mysql 执行此操作时,我总是遇到上述错误,就好像该指令被忽略一样。
我也尝试使用mysql_read_default_file相同的选项集,以及简单地mysql_skip_secure_auth在 DSN 中使用。这些东西的任何组合都没有奏效。
我错过了什么吗?
编辑:
跟踪输出(已编辑以删除敏感信息):
imp_dbh->mysql_dr_connect: host = |{host}|, port = 0, uid = {user}, pwd = {pwd}
imp_dbh->mysql_dr_connect: Skipping secure auth
imp_dbh->bind_type_guessing: …Run Code Online (Sandbox Code Playgroud) 我正在尝试为我用Python编写的javascript预处理器添加一些轻量级降价支持.
在大多数情况下它是有效的,但有时我使用的正则表达式有点奇怪,我认为它与原始字符串和转义序列有关.
正则表达式是: (?<!\\)\"[^\"]+\"
是的,我知道它只匹配以字符开头的"字符串.然而,这个项目出于好奇而不是任何事情,所以我现在可以忍受它.
要打破它:
(?<\\)\" # The group should begin with a quotation mark that is not escaped
[^\"]+ # and match any number of at least one character that is not a quotation mark (this is the biggest problem, I know)
\" # and end at the first quotation mark it finds
Run Code Online (Sandbox Code Playgroud)
话虽如此,我(显然)开始遇到这样的问题:
"This is a string with an \"escaped quote\" inside it"
我不太确定如何说"除了引号之外的所有内容,除非该标记被转义".我试过了:
([^\"]|\\\")+ # a group of anything but a quote or an …Run Code Online (Sandbox Code Playgroud) 我正在尝试设计一个界面来测试用户是否在该类中运行某些功能之前已登录.而不是:
class UserDoesStuff(object):
def doIfLoggedIn(self):
if self.checkLogin():
[...do the stuff...]
Run Code Online (Sandbox Code Playgroud)
我想知道我是否可以这样:
def protected(self):
if not self.checkLogin():
raise UserLoginError()
@protected
def doIfLoggedIn(self):
[...do the stuff...]
Run Code Online (Sandbox Code Playgroud)
这当然不起作用,但有没有办法使用装饰器来做到这一点?
我对如何正确声明从模板类继承的类感到困惑.
基类看起来像这样(不包括不相关的位):
template <class Writer>
class Node
{
Writer* writer;
...
public:
Node (std::string& root);
...
}
Run Code Online (Sandbox Code Playgroud)
声明和构造此类的继承类的正确方法是什么?我想的是:
template <class Writer>
class IndexNode : public Node
{...}
Run Code Online (Sandbox Code Playgroud)
但是,这样做会给我" expected class-name before '{' token".我已经尝试在继承的类中注释掉模板声明,认为模板声明本身可能是从父类继承的,但这也没有帮助,也尝试过
class IndexNode : template <class Writer> public Node
{...}
Run Code Online (Sandbox Code Playgroud)
,思考可能必须将模板显式附加到基类.我想而不是继续采取正确的组合,我会寻求帮助,并希望了解一些能让我理解其原因的东西.
谢谢!
我在使用 std::cout、std::stringstream 和 std::string.c_str() 时遇到了一些问题。主要是,似乎有些东西被困在某个地方的缓冲区中,我不知道如何解决这个问题。
如果您不喜欢在 StackOverflow 中阅读代码,这里是我 github 的相关链接:TLString 类、测试类和单元测试——您可以跳到我陈述更简洁问题的最后。
在我的单元测试中,我有以下代码:
Test <std::string> strtest; // A unit test object expecting strings.
Test <const char*> chtest; // A unit test object expecting const char*s
// ...
TurnLeft::Utils::TLString str3("Exterminate.");
// ...
/* Basically, name() and expect() will use the passed arg.
* in the output in order to
* display output such as the following:
* str(): expecting 'Exterminate.' | Actual 'Exterminate.' => PASS
*/ …Run Code Online (Sandbox Code Playgroud) python ×5
c++ ×2
inheritance ×2
c-strings ×1
centos ×1
coverage.py ×1
cron ×1
dbi ×1
decorator ×1
perl ×1
perl-module ×1
pytest ×1
pytest-cov ×1
regex ×1
string ×1
stringstream ×1
super ×1
superclass ×1
templates ×1
tox ×1
vim ×1