Debugging — Software Engineer
This debugging exercise asks you to locate and correct defects in a Python templating-library repository. You will be given a repository containing a deliberately altered copy of the Mako template engine. Use the test suite along with your debugging approach to discover and describe the defects.
This assessment evaluates how well you can explore an unfamiliar project, rapidly reason about nontrivial code, apply debugging tools, and clearly narrate your reasoning.
Repository: You will receive access to the repository for this exercise.
Mako is a popular Python templating system that turns templates into Python modules to improve runtime performance. Its major capabilities include:
<%... %> blocks${variable}<%inherit><%def> elementsExample Template:
<%inherit file="layout.html"/>
<%def name="welcome(person)">
Welcome, ${person}!
</%def>
% for product in products:
<li>${product}</li>
% endfor
You are not expected to know Mako beforehand; the project’s extensive tests should guide you toward the broken behavior.
debug-mako directory.pip install -r bugsquash-requirements.txt.python -m pytest test/.The repository provides a complete implementation of a template library:
mako/
├── template.py # Primary Template type and render behavior
├── lexer.py # Breaks template text into tokens
├── codegen.py # Builds Python code from parsed templates
├── ast.py # AST-node declarations for template constructs
├── _ast_util.py # Helpers for working with ASTs
├── lookup.py # Finds template files and manages caching
├── runtime.py # Runtime context and helper functionality
├── parsetree.py # Parse-tree node declarations
├── pygen.py # Produces Python source code
├── pyparser.py # Parses Python expressions
├── filters.py # Functions that filter rendered output
├── cache.py # Template-cache implementation
├── exceptions.py # Library-specific exception types
├── cmd.py # Command-line entry point
├── compat.py # Compatibility support across Python versions
└── util.py # Shared utility helpers
test/
├── test_template.py # Tests for fundamental template rendering
├── test_lexer.py # Tests for lexing and tokenization
├── test_lookup.py # Tests for locating and loading files
├── test_ast.py # Tests for AST processing
└──... # Other test modules
Start With the Entire Test Suite: First, see the full set of failures.
python -m pytest test/ -v
Narrow Down Individual Failures: Re-run a failing test by itself to get more focused output.
python -m pytest test/test_lookup.py::TestClass::test_name -v
Inspect the Tests: Determine the behavior that each test is asserting.
Follow the Execution Path: Trace processing from the test’s input through to the point where it fails.
Use Print Statements or pdb: Add breakpoints when you need to examine program state.
import pdb; pdb.set_trace()
Review Suspicious Modifications: Examine code regions that look unusual or internally inconsistent.
Defects in this repository commonly fit the following patterns: