Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Codewars Python TDD脱机_Python_Tdd_Codewars - Fatal编程技术网

Codewars Python TDD脱机

Codewars Python TDD脱机,python,tdd,codewars,Python,Tdd,Codewars,我想使用我熟悉的开发环境离线执行Codewars Python katas。但是,提供的测试使用了与Python的Unittest完全不同的语法。我在任何地方都找不到测试框架的源代码 我尝试过codewars客户端npm包(),但它让我非常困惑。我也看过codewars cli runner,但这看起来更难理解,而且涉及Docker 这是令人沮丧的,因为我真的只是想练习一些基本的编码,但我最终不得不尝试理解json和依赖项以及包管理,只是为了让一个基本的TDD环境启动并运行 有谁能建议如何简单地

我想使用我熟悉的开发环境离线执行Codewars Python katas。但是,提供的测试使用了与Python的Unittest完全不同的语法。我在任何地方都找不到测试框架的源代码

我尝试过codewars客户端npm包(),但它让我非常困惑。我也看过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%")

我建议使用类似 您可以使用当前示例或搜索其他一些代码kata。
其原理与“代码战争”相同——它使用测试来检查您的答案。主要的好处是,您可以在您的机器上设置它并脱机使用。(据我所知,这对您很重要)

我只是将测试用例转换为代码中的打印语句,并注释掉其余的语句。然后目视比较答案

见下文:

# 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%"

我使用自己的类来模拟代码战测试行为

您可以在这里看到我的示例:

您可以自己实现这些函数,将它们放在名为test.py的文件中并导入。topcoder还有seri/gettc,我和它在一起的时间比shime/codewars要好。有时我不得不修复测试代码中的小错误或手动验证,因为在使用gettc时有多个可接受的答案