所以我想做这个代码Kata练习.我想在单独的文件中用tdd实现kata:
算法:
# stringcalculator.py
def Add(string):
return 1
Run Code Online (Sandbox Code Playgroud)
和测试:
# stringcalculator.spec.py
from stringcalculator import Add
import unittest
class TestStringCalculator(unittest.TestCase):
def add_returns_zero_for_emptyString(self):
self.assertEqual(Add(' '), 0)
if __name__ == '__main__':
unittest.main()
Run Code Online (Sandbox Code Playgroud)
运行测试文件时,我得到:
Ran 0 tests in 0.000s
OK
Run Code Online (Sandbox Code Playgroud)
但它应该返回一个失败的测试.我在这里想念什么?
我已经成功安装了Google Test .
我的问题如下:我必须测试正在为具有32位操作系统的嵌入式软件开发的项目,因此我需要从64位重新配置Google Test.
使用旧的1.7.0版本,它知道解决方案是这样的:
autoreconf -fvi
./configure --build=i686-pc-linux-gnu "CFLAGS=-m32" "CXXFLAGS=-m32" "LDFLAGS=-m32"
make
Run Code Online (Sandbox Code Playgroud)
这就是我现在尝试使用新版本的方法:
cd home/CWD/googletest/googlemock
autoreconf -fvi
./configure --build=i686-pc-linux-gnu "CFLAGS=-m32" "CXXFLAGS=-m32" "LDFLAGS=-m32"
cd home/CWD/googletest/googletest
autoreconf -fvi
./configure --build=i686-pc-linux-gnu "CFLAGS=-m32" "CXXFLAGS=-m32" "LDFLAGS=-m32"
cd ..
mkdir googletest_build
cd googletest_build
cmake -DCMAKE_INSTALL_PREFIX:PATH=/home/me/googletest ../googletest
make
make install
Run Code Online (Sandbox Code Playgroud)
这样做,因为我在其他地方找不到配置文件,但终端中显示的结果与1.7.0版本的重新配置相同.
但使用后:
make UTEST=yes project_Name
Run Code Online (Sandbox Code Playgroud)
我明白了:
Linking... project_Name
GTEST_LDFLAGS=-L ../../googletest//lib/ -lpthread -lgtest -lgtest_main -lgmock -lstdc++!
/usr/bin/ld: skipping incompatible ../../googletest//lib//libgtest.a when searching for -lgtest
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../libgtest.a when searching for -lgtest
/usr/bin/ld: skipping incompatible //usr/lib/libgtest.a …Run Code Online (Sandbox Code Playgroud) 我有这样的疑问:
SELECT COUNT(DISTINCT Serial, DatumOrig, Glucose) FROM values;
Run Code Online (Sandbox Code Playgroud)
我尝试用SQLAlchemy这种方式重新创建它:
session.query(Value.Serial, Value.DatumOrig, Value.Glucose).distinct().count()
Run Code Online (Sandbox Code Playgroud)
但这转化为:
SELECT count(*) AS count_1
FROM (SELECT DISTINCT
values.`Serial` AS `values_Serial`,
values.`DatumOrig` AS `values_DatumOrig`,
values.`Glucose` AS `values_Glucose`
FROM values)
AS anon_1
Run Code Online (Sandbox Code Playgroud)
它不会内联调用 count 函数,而是将select unique包装到子查询中。
我的问题是: SQLAlchemy 有哪些不同的方法来计算多列上的不同选择以及它们会转换成什么?
有什么解决方案可以转化为我原来的查询吗?性能或内存使用情况有什么严重差异吗?
在这个问题之后,我知道如何检查我的函数是否被装饰。
只是我需要更多信息,即实际应用于函数的装饰器(或者在调用函数时调用,如果它更适合的话)。
为了避免这个答案中提到的危险,我正在使用functools.wraps. 这样我就不必小心所使用的包装器的任何命名重新定义。
这是我到目前为止所拥有的:
from functools import wraps
def decorator_wraps(function):
@wraps(function)
def _wrapper(*a, **kw): ...
return _wrapper
def is_decorated(func):
return hasattr(func, '__wrapped__')
@decorator_wraps
def foo(x, y): ...
print(is_decorated(foo)) # True
Run Code Online (Sandbox Code Playgroud)
但我需要的是:
from functools import wraps
def decorator_wraps_1(function):
@wraps(function)
def _wrapper(*a, **kw): ...
return _wrapper
def decorator_wraps_2(function):
@wraps(function)
def _wrapper(*a, **kw): ...
return _wrapper
def decorators(func):
# returns list of decorators on `func`
# OR
def is_decorated_by(func, decorator):
# returns True if `func` is decorated …Run Code Online (Sandbox Code Playgroud) 我正在尝试根据这个答案在没有 root 访问权限的 Ubuntu 上安装 Google Test ,因为我需要在工作中学习和使用它。
设法在我自己的用户文件夹中完成这些:
$ mkdir ~/temp
$ cd ~/temp
$ unzip gtest-1.7.0.zip
$ cd gtest-1.7.0
$ mkdir mybuild
$ cd mybuild
$ cmake -DBUILD_SHARED_LIBS=ON -Dgtest_build_samples=ON -G"Unix Makefiles" ..
$ make
Run Code Online (Sandbox Code Playgroud)
似乎我已经在 /usr/src/gtest 中安装了 gtest 虽然我不想使用它,因为不是我安装了它,我不确定它的版本,也不确定它的可用性。未经许可甚至不能删除它。
仍然指令结束为:
$ cp -r ../include/gtest ~/usr/gtest/include/
$ cp lib*.so ~/usr/gtest/lib
Run Code Online (Sandbox Code Playgroud)
我在这里缺少什么?
是的。我已经这样做了。这是愚蠢的。
我不知道它会自己依赖它,只想从头开始安装 python 2 和 3(因为这个问题:https : //askubuntu.com/questions/897355/how-to-change-default-idle -for-python)。
现在,我仍然可以使用我的终端,检查这些答案:
https://askubuntu.com/questions/741265/apt-get-remove-python-150mb-apt-get-install-python-687kb
https://askubuntu.com/questions/437644/i-accidentaly-did-sudo-apt-get-remove-python
但是运行后sudo apt-get install ubuntu-desktop我收到这些错误:
Setting up python-ldb (2:1.1.24-1ubuntu3) ...
/var/lib/dpkg/info/python-ldb.postinst: 6: /var/lib/dpkg/info/python-ldb.postinst: pycompile: not found
dpkg: error processing package python-ldb (--configure):
subprocess installed post-installation script returned error exit status 127
No apport report written because MaxReports is reached already
Setting up python-tdb (1.3.8-2) ...
/var/lib/dpkg/info/python-tdb.postinst: 6: /var/lib/dpkg/info/python-tdb.postinst: pycompile: not found
dpkg: error processing package python-tdb (--configure):
subprocess installed post-installation script returned error exit status …Run Code Online (Sandbox Code Playgroud) 我正在做以下事情:
array_variable = collection.map do |param|
some value with param
end
return array_variable.compact
Run Code Online (Sandbox Code Playgroud)
我可以打电话map,并compact在某种程度上一条语句,这样我就可以立即返回结果?
我正在考虑这样的事情(但可能无效):
array_variable = block_code param.compact
# block_code here is a method for example which fills the array
Run Code Online (Sandbox Code Playgroud) 我想按照这个课程设置和学习laravel:https://laracasts.com/series/laravel-from-scratch-2017/episodes/4
当我尝试使用该命令时,php artisan migrate我收到此错误:
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [1045] Access denied for user 'laravel'@'localhost' (using password: NO) (SQL: select * from information_schema.tables whe
re table_schema = laravel and table_name = migrations)
[PDOException]
SQLSTATE[HY000] [1045] Access denied for user 'laravel'@'localhost' (using password: NO)
Run Code Online (Sandbox Code Playgroud)
试图寻找答案,我想我可能会对.env文件进行一些更改,但不知道到底是什么,到目前为止还没有任何工作.
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=laravel
DB_PASSWORD=
Run Code Online (Sandbox Code Playgroud)
我在视频中使用Ubuntu 16.04而不是Mac OS X,所以我想知道我该怎么办?有没有我没做过的mysql设置?
由于干净的代码原因,我想对主要的 Model 方法隐藏某些实现。我不希望我的模型包含很多庞大的方法,只包含最清晰和冗长的功能。
例如:
class SomeModel
#included stuff
#fields & attrs
def modelMethod
variable = functionality1(functionality2)
if some condition
functionality3
else
functionality4
end
end
Run Code Online (Sandbox Code Playgroud)
我应该将我的功能方法放在同一模型文件末尾的aprivate或protectedpart下,还是应该将它们放入帮助文件中?
如果我是对的,助手中的代码仅用于视图。这是什么约定?
所以在终端中使用vim,我可以使用ctrl + pgdown,ctrl + pgup在vim标签页之间导航.但是,如果我打开tmux中的文件,我会丢失这些键绑定.
在tmux中执行此操作的命令是什么?
ALTER TABLE table_name
ALTER COLUMN columnWithDate datetime;
Run Code Online (Sandbox Code Playgroud)
columnWithDate是nvarchar(255)的一种,数据采用2018.06.19.形式。我检查了所有不同的值,并且columnWithDate中有一行具有NULL值。
我在alter命令中遇到以下错误runninf:
The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.
Run Code Online (Sandbox Code Playgroud)
我在这里想念什么?
python ×4
ubuntu ×3
googletest ×2
linux ×2
sql ×2
32bit-64bit ×1
apt ×1
decorator ×1
helper ×1
installation ×1
laravel ×1
laravel-5.4 ×1
model ×1
mysql ×1
orm ×1
php ×1
ruby ×1
ruby-block ×1
samba ×1
sql-server ×1
sqlalchemy ×1
terminal ×1
tmux ×1
ubuntu-16.04 ×1
unit-testing ×1
vim ×1