小编Arj*_*tra的帖子

AssertionError,虽然预期的调用看起来与实际调用相同

我在 django 中做了一个调用函数的命令。该函数执行 django orm 调用:

def get_notes():
    notes = Note.objects.filter(number=2, new=1)
    return [x.note for x in notes]
Run Code Online (Sandbox Code Playgroud)

我想修补实际查找:

@mock.patch('Note.objects.filter', autospec=True)
def test_get_all_notes(self, notes_mock):
    get_notes()
    notes_mock.assert_called_once_with(number=2, new=1)
Run Code Online (Sandbox Code Playgroud)

我收到以下断言错误:

AssertionError: Expected call: filter(number=2, new=1)
Actual call: filter(number=2, new=1)
Run Code Online (Sandbox Code Playgroud)

我在 google 和 stackoverflow 上搜索了几个小时,但我仍然没有任何线索。谁能指出我正确的方向,我认为这可能是我犯的一个明显错误......

python django mocking

5
推荐指数
1
解决办法
2447
查看次数

Haskell加入getHomedirectory字符串

我有一个包含代表目录的字符串的文件.其中一些字符串中有一个波浪号(〜).我想将用户的homedirectory(〜)加入到字符串的其余部分.到目前为止我所拥有的:

import Data.List (isPrefixOf)
import System.Directory (doesDirectoryExist, getHomeDirectory)
import System.FilePath (joinPath)

getFullPath s
    | "~" `isPrefixOf` s = joinPath [getHomeDirectory, tail s]
    | otherwise          = s
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

Couldn't match type `IO FilePath' with `[Char]'Expected type: FilePath Actual type: IO FilePathIn the expression: getHomeDirectoryIn the first argument of `joinPath', namely `[getHomeDirectory, tail s]'In the expression: joinPath
Run Code Online (Sandbox Code Playgroud)

我不知道,我找不到,如何转换类型,使它们匹配,并可以连接在一起.

string haskell filepath

2
推荐指数
1
解决办法
850
查看次数

标签 统计

django ×1

filepath ×1

haskell ×1

mocking ×1

python ×1

string ×1