/adapters/select_ connection.py ", line 366, in Process_timeouts
Timer[' callback '] ()
File "/home/appleyuchi/.virtualenvs/python2.7/local/lib/python2.7/site-packages/pika/adapters/blocking_ connection.py ", line, in Signal_once
Assert not Self._ready, ' _callbackresult is already set '
Assertionerror: _callbackresult was already set
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801,
have successfully tested two common cases. Now let's consider boundary situations, or use cases that are unusual or unexpected input. When you test a function with a positive integer in the range, the instances under the boundary condition include 0, 1, negative, and a large number. Now let's test some of them.
It is easy to add a 0-to-0 Test. What we expect? Is_prime (0) returns false because, according to definition, the prime number must be greater than 1.
def test_is_zero_not_prime(self):
)) self.assertEquals("V", self.cvt.convert_to_roman(5)) self.assertEquals("XII", \ self.cvt.convert_to_roman(12)) self.assertEquals("MMX", \ self.cvt.convert_to_roman(2010)) self.assertEquals("MMMM", \ self.cvt.convert_to_roman(4000))if __name__ == "__main__": unittest.main()
Result output: (this result makes it hard to figure out which use cases have errors. It is not as clear as the follo
Python common exception classification and handling methods, python Processing Methods
Common Python exception typesIt can be divided into the following categories:
1. AssertionError: The exception thrown when the assert asserted condition is false.
2. AttributeError: exception thrown when the accessed object property
Advanced Python Applications (iii) object-oriented programming step-by-stepKey points to learn in this chapter:
Object-oriented Advanced Syntax section
Static methods, class methods, property methods
Special methods for classes
Reflection
Exception handling
Socket Development Basics
first, the object-oriented Advanced Syntax sectionStatic methodsTo use a static method in a class, precede the class mem
consider boundary situations, or use cases that are unusual or unexpected input. When you test a function with a positive integer in the range, the instances under the boundary condition include 0, 1, negative, and a large number. Now let's test some of them.
It is easy to add a 0-to-0 test. What we expect? Is_prime (0) returns false because, according to definition, the prime number must be greater than 1.
def test_is_zero_not_prime(self): """Is zero correctly determined not to be prime?"""
throws it again after _ exit _ ends.
The ability to capture exceptions creates interesting possibilities. A classic example from unit test -- we want to ensure that some code throws the correct type of exception:
class assert_raises(object): # based on pytest and unittest.TestCase def __init__(self, type): self.type = type def __enter__(self): pass def __exit__(self, type, value, traceback): if type is None: raise AssertionError('e
Python reference manual, python reference manual chmImportant built-in functions of expressions
# Function # description ------------------------------------------------------------------------------------------------- abs (numbers) # returns the absolute value of A number apply (func [, arg [, kwargs]) # calls a given function, optional parameter all (iterable) # True is returned if all iterable elements
StandardError
All base classes with built-in standard exceptions
ArithmeticError
Base classes with incorrect numeric calculation
FloatingPointError
Floating Point Calculation Error
OverflowError
The value operation exceeds the maximum limit.
ZeroDivisionError
Except (or modulo) zero (all data types)
AssertionError
Assertion statement failed
AttributeError
The object d
Assertions in Python are simple to use, and you can keep up with arbitrary criteria after an assert, and throw an exception if the assertion fails.
>>> Assert 1 + 1 = 2
>>> assert isinstance (' hello ', str)
>>> assert isinstance (' Hello ', int '
traceback (most recent call last):
File "
The assert looks good, but it's not fun to use. Just like someone tells you that the program is wrong, but don't tell me what's wrong. A lot of times such an ass
This is not a comprehensive introduction to Python exceptions. it is just a note-taking record and summary article after learning Python exceptions, this is not a comprehensive introduction to Python exceptions. it is just a note-taking record and summary article after learning Python exceptions. What? You don't know w
the Thread object. The second Method inherits threading. thread defines subclass and overwrites the run () method. In the second method, the only method that must be overwritten is run (). You can decide whether to rewrite _ init _ () as needed __(). It is worth noting that to override _ init _ (), the _ init _ () of the parent class must be called in the first line of the function, otherwise, the error "AssertionError: Thread. _ init _ () not called
Python BASICS (11): errors and exceptions, 2015 python
During the execution of the program, exceptions may occur, and errors may be fatal in the previous period. Later, with the development of the program, the handling methods of some errors will be gentle, when an error occurs, some diagnostic information and fuzzy prompts are generated. Help us handle exceptions.I will learn
Baptism soul, practice python (2) -- python installation and configuration, python -- python
Install python and basic configurations:
Python Official Website: www.python.org
Open the website and download the corresponding version
): # through d[' empty '] When accessing a key that does not exist, the assertion throws Keyerror
value = d[' empty '
def test_attrerror (self):
d = Dict ()
with Self.assertraises (Attributeerror): # When accessing nonexistent key via D.empty, we expect to throw attributeerror
value = D.empty
if __ name__ = = ' __main__ ':
unittest.main ()
Just run mydict_test.py as a normal Python script.
O
This article mainly introduces python exception-related information and sorts out relevant exception information. if you need it, you can refer to it recently. a small project may encounter Python exceptions, which is a headache, therefore, sort out exceptions to avoid confusion next time. The following describes how to organize Python exceptions.
1.
Python exception handling summary, python exception handling
This article details common exception handling in Python for your reference. The details are as follows:
1. Throw an exception or custom exception
Python uses an exception object to indicate exceptions. An exception is thrown when an error occurs. If the exce
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.