我有多个分支从主服务器分支(每个分支在一个单独的子目录中).
在完成修补程序的测试之前,我想在Branch1中已经有代码,所以我可以继续开发修复程序.
(但是因为我对git的经验并不是那么多,所以我第一次开始在第三个分支中进行合并,特别是在我弄乱了Branch1或Branch2之前就已经陷入困境)
在我的第3分支中,我首先尝试了以下内容:
git merge feature/Branch1
Run Code Online (Sandbox Code Playgroud)
但是这给出了以下错误:
fatal: 'feature/Branch1' does not point to a commit
Run Code Online (Sandbox Code Playgroud)
我接下来在我的Branch1中做了一个提交-a并再次尝试,但它一直给出同样的错误.
我究竟做错了什么?我应该怎么做才能合并代码 - 在这种情况下 - Branch1与Branch3?
与其说是一个知识共享问题.
根据GoogleMock 常见问题解答,无法模拟可变参数函数,因为不知道将为函数提供多少参数.
这是事实,但在大多数情况下,人们知道从被测系统调用可变参数函数有多少变量,或者如何将可变参数转换为1个非变量参数.
我的一位同事(不知道他是否在Stackoverflow上活动)想出了一个工作解决方案,如下面的例子所示(使用模拟器进行C型接口):
class MockInterface
{
public:
MockInterface() {}
~MockInterface() {}
MOCK_METHOD4( variadicfunction, void( const std:: string name, AN_ENUM mode,
const std::string func_name, const std::string message ) );
};
boost::shard_ptr<MockInterface> mock_interface;
extern "C"
{
void variadicfunction( const char *name, AN_ENUM mode,
const char *func_name, const char *format, ... )
{
std::string non_variadic("");
if (format != NULL )
{
va_list args;
va_start( args, format );
// Get length of format including arguments
int nr = vsnprintf( NULL, 0, …Run Code Online (Sandbox Code Playgroud) 我发现了许多看起来像我的问题,但是没有产生我可以使用的解决方案(最近的问题是:子进程输出到stdout和PIPE)
问题:我想使用需要很长时间的子流程来启动流程。运行命令后,我需要解析stdout-output和stderr-output。
目前,我这样做如下:
p = subprocess.Popen( command_list, stdout=subprocess.PIPE,
stderr=subprocess.PIPE )
out, error_msg = p.communicate()
print out + "\n\n" + error_msg
#next comes code in which I check out and error_msg
Run Code Online (Sandbox Code Playgroud)
但是此方法的缺点是,用户在运行过程中看不到该过程的输出。仅在最后输出。
有没有一种方法可以在命令运行时打印输出(就像我给出的命令没有stdout / stderr = subprocess.PIPE一样),并且最终还是通过p.communicate输出?
注意:我目前正在使用python 2.5(使用此python版本的旧软件版本)进行开发。
我正在为某些激光驱动器功能创建一些测试。对于某些激光器,支持一项子功能,而在其他激光器上,我应该预期会出现错误(从而测试是否会引发错误)。当然,子功能不是 1 个功能,而是多个功能(为了简单起见;-))。因此,对于特定的激光器,特定功能的测试应该通过或失败。
通过的情况不是问题,但是当它失败并且函数有多个返回值时,我们创建的通用断言就会出现问题,它不知道应该返回多少个返回值给测试函数,因此我们的如果激光器不支持子功能,则通用断言仅返回 1 无值。
因此,我们必须检查具有多个返回值的函数的测试是否失败或通过,并且只有我们才能以正确的方式调用通用断言。
但这有点丑陋,恕我直言,因为在这种情况下,我们会检查子功能是否受支持两次(通用断言的目标是在一个地方执行此操作)。
有没有办法在调用函数之前确定函数的返回值数量?
伪代码中的问题:
通用断言(加上测试的基本设置):
import functionality_under_test as fut
class Functionality( unittest.TestCase ):
def shared_setup( self ):
Functionality._issupported = fut.subfunctionality.is_supported()
def _assert_sub_functionality( self, func, *args, **kwargs ):
retval = None # We don't know how many retvals there will be
if not self._issupported:
# Here is the place where it should determine how many
# return-values func really has and initialize retval as
# with the correct number of None's in a tuple / …Run Code Online (Sandbox Code Playgroud) 我有一个函数,它使用同一个类的 2 个实例,我想使用 python 模拟来测试该函数。但我很头疼我怎么能嘲笑这个。我已经使用我的朋友 Google 和 Stackoverflow 来寻找解决方案,但到目前为止还没有找到任何解决方案。
作为简单的模拟示例,它显示了我要测试的原理:
class MyClass(object): # this class is inside a module I'm not allowed to change.
def __init__(self, name, value):
self._name = name
self._value = value
def get_value(self):
return self._value
Run Code Online (Sandbox Code Playgroud)
然后是被测模块(再次是一个模拟实现来展示这个想法):
import my_class_module
def my_function():
a = my_class_module.MyClass('a', 3)
b = my_class_module.MyClass('b', 4)
return a.get_value() + b.get_value()
Run Code Online (Sandbox Code Playgroud)
我想到的 my_function 的单元测试的全局想法如下(但这个想法目前当然行不通):
mock.patch('module.my_class_module.MyClass')
def test_my_function(self, mock_my_class):
def _my_get_value(self): # ideally I would like to use get_value.return_value per instance, but I don't know how.
if …Run Code Online (Sandbox Code Playgroud)