Unsupported Location Error
Calling certain Python libraries from within a magic method or unit test function can cause a platform error. The program will stop executing immediately, and rather than the standard runtime error behavior, the following popup will appear:
Due to how this error works, the platform cannot pinpoint the line that caused it. Read on to find the common causes of this error.
What Is A System Function Call?
Certain libraries, both built into Python and provided by TechSmart, interact with the system in low-level ways that must be specially handled by the TechSmart platform for security. When functions from these libraries are called from certain places in code, the platform cannot execute them in the correct way, which causes the Unsupported Location Error.
These modules contain system function calls that can cause Unsupported Location errors:
- tsapp - Creating and displaying graphical elements or sounds
- pygame - Creating and displaying graphical elements or sounds
- requests - Sending an HTTP request
Typecast Magic Methods
Students should avoid calling system functions within magic methods that typecast a value. (Note: For more on magic methods, they are covered in Lesson 9.2 of C204, “Customizing Classes.”)
Here is a complete list of all common magic methods, and whether they can cause the Unsupported Location error:
System Functions Supported
|
System Functions NOT Supported (Can cause Unsupported Location) |
__add__() __sub__() __mul__() __div__() __truediv__() __floordiv__() __eq__() __ne__() __lt__() __gt__() __le__() __ge__()
|
__int__() __float__() __str__() |
Unit Tests
Students should avoid calling system functions within test methods of a subclass of unittest.TestCase. Any method called automatically by unittest.main() is an unsupported location. That means any test method within a subclass of unittest.TestCase is liable to cause an Unsupported Location error. (Note: For more information on test classes, look to Lesson 9.5 of C204, “Unit Tests.”)
What if I need to automatically test graphics, sound or HTTP responses?
Certain functions, such as creating graphical objects or getting an HTTP request, contain system operations. However, accessing the methods of the resulting objects can be safely done from any location. In practice, that means that instead of creating these objects within the test class you would create them as global variables, or create functions to retrieve them in the module being tested. Then, you can retrieve data from them within test methods without having to repeat the risky system operation.