In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about how to parse the Python operator style, which may not be well understood by many people. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
Calling a method affects readability. Although the name of the assertEqual () method indicates that you want to test whether the two values are equal, the code still doesn't look like a comparison and is not as clear as the Python operator for developers familiar with the Python operator.
Second, as you will see in the third article in this series, the new testing framework now knows how to check assert statements to identify the conditions that caused the test to fail. This means that simple assert statements can now generate meaningful test failure messages.
It provides information similar to the result of calling old methods such as assertEqual (). *, even though assertEqual () is still necessary, importing this function from the test module (rather than making it available through class inheritance) is certainly easier and more in line with the style of the Python operator.
In fact, as you'll see below, when py.test and nose want to provide more routines to support testing, they simply define those routines as functions, which users can then import into their own code. Of course, if the author does need to cache through the routine.
# nose.tools support functions for writing tests assert_almost_equal (first, second, places=7, msg=None) assert_almost_equals (first, second, places=7, msg=None) assert_equal (first, second, msg=None) assert_equals (first, second, msg=None) assert_false (expr, msg=None) assert_not_almost_equal (first, second, places=7, msg=None) assert_not_almost_equals (first, second, places=7, msg=None) assert_not_equal (first, second, msg=None) assert_not_equals (assert_not_equals, first Msg=None) assert_true (expr, msg=None) eq_ (a, b, msg=None) ok_ (expr, msg=None)
However, if programmers want to write simple test code and don't want to think about the clutter involved in doctest, then test functions are a good way to do it. In short, test functions can greatly enhance the ease of writing tests. Programmers don't have to remember, rewrite, or copy previously written test code, and the new convention allows Python programmers to write tests like normal Python operators: just open an empty file and type!
Both the py.test and nose frameworks provide special routines that simplify the writing of tests. It can be considered that they provide a convenient test "dialect", which can be used to write tests. This simplifies test writing and reduces errors, and makes tests shorter and more readable.
However, using these routines can also lead to an important consequence: your tests are bundled with the framework that provides functions and lose compatibility. Therefore, there is a tradeoff between convenience and compatibility. If you write all the tests from scratch using only the clumsy standard Python operator unittest module, they can run in any test framework.
Further, if you write the test function in a simple way (as described above), the test can at least be run in py.test and nose. But. If you start using features specific to one test framework, you must rewrite tests if you decide to migrate the framework if another framework develops new and important features later.
Both py.test and nose provide alternatives to TestCase's assertRaises () method. The version provided by py.test is relatively new, and it can also accept strings to execute, which is more powerful because you can test expressions that throw exceptions, rather than just function calls:
# conveniences.py import math import py.test py.test.raises (OverflowError, math.log, 0) py.test.raises (ValueError, math.sqrt,-1) py.test.raises (ZeroDivisionError, "1 / 0") import nose.tools nose.tools.assert_raises (OverflowError, math.log, 0) nose.tools.assert_raises (ValueError, math.sqrt,-1) # No equivalent for third example!
When dealing with floating-point numbers, if you want the test to be flexible with the implementation of the Python operator, allowing for small errors in the processing of floating-point numbers, then the above routine that checks for approximate values is particularly meaningful.
After reading the above, do you have any further understanding of how to parse the Python operator style? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un