Unit Testing with Python (Part 4) – File Operations

Previously (here, here and here) we looked at users.py and how we can create a set of tests using mocks to validate it’s working as intended. The subject we were mocking in those previous examples was file_utils.py. Here’s what file_utils.py looks like; def write_file(path, content): file_to_write = open(path, "w") file_to_write.write(content) file_to_write.close() def read_file(path): with open(path, […]

Python JSON Tutorial

The JSON module is part of the Python standard library and provides an easy to use way of dealing with JSON data types. This tutorial servers as a basic introduction to this very useful module. Python to JSON table The first place to start is the Python to JSON table (defined in the documentation) which […]