3
在测试和生产代码之间复制常量?
在测试和真实代码之间复制数据是好是坏?例如,假设我有一个Python类FooSaver,该类将具有特定名称的文件保存到给定目录: class FooSaver(object): def __init__(self, out_dir): self.out_dir = out_dir def _save_foo_named(self, type_, name): to_save = None if type_ == FOOTYPE_A: to_save = make_footype_a() elif type == FOOTYPE_B: to_save = make_footype_b() # etc, repeated with open(self.out_dir + name, "w") as f: f.write(str(to_save)) def save_type_a(self): self._save_foo_named(a, "a.foo_file") def save_type_b(self): self._save_foo_named(b, "b.foo_file") 现在,在我的测试中,我想确保所有这些文件均已创建,因此我想说一下这样的话: …