python - Codewars Python TDD 离线

标签 python tdd

我想使用我熟悉的开发环境离线执行 Codewars Python 套路。然而,所提供的测试使用与 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%")

最佳答案

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

见下文:

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

关于python - Codewars Python TDD 离线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40996317/

相关文章:

java - 编写Gradle插件时如何测试afterEvaluate

python - 将 JSON 写入文件而不将转义反斜杠写入文件?

python - 获取与 Beautiful Soup 的字符串列表中的字符串匹配的 HTML href 链接

node.js - Jasmine Node 测试子进程

javascript - Angularjs 和 Jasmine : testing with multiple instances of the same service

php - Zend Framework 与 Behat BDD 集成

python - 每个不使用 self 参数的方法都应该是静态类吗?

Python - 为什么我可以在没有 __init__.py 的情况下导入模块?

python - 使用python解析带有按钮 "Load More"的网页

.net - 在进行 BDD 时,我是否必须首先对通过验收测试所需的每段代码进行 TDD?