在我的代码release_bundler.py文件中
class MavenDependenciesPathsBuilderStrategy(PathsBuilderStrategy):
def build_bundler_copy_paths(self, mapping_values):
source = join(getcwd(),'target','dependency',mapping_values[0])
destination = join(getcwd(),'target','generated-resources',mapping_values[1],mapping_values[0])
return [source, destination]
class NestedModulePathsFilterStrategy(FilterStrategy):
def filter_changeset_paths(self, changeset_paths, bundling_map, paths_builder_strategy):
for mapping_key in bundling_map.keys():
if(mapping_key in changeset_paths):
mapping_values = bundling_map.get(mapping_key).values()
copy_paths = paths_builder_strategy.build_bundler_copy_paths(mapping_values)
return copy_paths
如果我想测试该filter_changeset_paths方法,我必须在getcwd方法内模拟这两种方法,build_bundler_copy_paths还是只模拟后者呢?
我尝试在我的测试中模拟该方法release_bundler_test.py,导入如下分类:
from release_bundler import NestedModulePathsFilterStrategy, MavenDependenciesPathsBuilderStrategy
然后修补MavenDependenciesPathsBuilderStrategy课程
def mock_build_bundler_copy_paths(self, mapping_values):
return ['/cwd/foo','/cwd/bar']
但我不认为这个模拟有效,因为self.assertIsNotNone(result)失败
所以问题是:
我嘲笑的方式正确吗?无法理解
会嘲笑该MavenDependenciesPathsBuilderStrategy方法还是我也必须嘲笑os.getcwd它的内部方法?
相关分类