Codewars Python TDD 离线

4
我想使用熟悉的开发环境离线完成Codewars Python katas,但是提供的测试使用与Python的Unittest完全不同的语法。我找不到测试框架的源代码。
我尝试了codewars-client npm包(https://github.com/shime/codewars),但它让我深感困惑。我还看了codewars-cli runner,但那看起来更难以理解,并涉及Docker。
这很令人沮丧,因为我真的只想练习一些基本编程,但最终却必须尝试理解json、依赖项和软件包管理,才能建立一个基本的TDD环境。
请问有人可以建议如何简单地使用提供的Python katas测试?以下是示例:
test.describe("Basic tests")
test.it("A resistor under 1000 ohms and with only three bands")   
test.assert_equals(decode_resistor_colors("yellow violet black"), "47 ohms, 20%")
test.it("A resistor between 1000 and 999999 ohms, with a gold fourth band")   
test.assert_equals(decode_resistor_colors("yellow violet red gold"), "4.7k ohms, 5%")
test.it("A resistor of 1000000 ohms or above, with a silver fourth band")   
test.assert_equals(decode_resistor_colors("brown black green silver"), "1M ohms, 10%")

1
你可以自己实现这些函数,将它们放在一个名为test.py的文件中并进行导入。对于Topcoder,还有seri/gettc可供使用,我使用它比shime/codewars更好。偶尔我不得不修复测试代码中的小错误或手动验证,因为使用gettc时有多个可接受的答案。 - jonatan
2个回答

1
我只是将测试用例转换为我的代码中的打印语句,并注释掉其余部分。然后进行视觉比较答案。
请参见下面:
# test.describe("Basic tests")
# test.it("A resistor under 1000 ohms and with only three bands")   
print(decode_resistor_colors("yellow violet black")) # "47 ohms, 20%"

# test.it("A resistor between 1000 and 999999 ohms, with a gold fourth band")   
print(decode_resistor_colors("yellow violet red gold")) #  "4.7k ohms, 5%"

# test.it("A resistor of 1000000 ohms or above, with a silver fourth band")   
print(decode_resistor_colors("brown black green silver")) # "1M ohms, 10%"

0

我建议使用类似python-code-kata这样的东西。 你可以使用当前的例子或搜索其他的代码卡塔。 原则与“codewars”相同-它使用测试来检查您的答案。 主要好处是您可以在计算机上设置它并离线使用它。 (我理解这对您很重要)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接