Academy Tester (Python)
This package contains functions to streamline testing tasks in the Jetbrains Academy plugin available in PyCharm.
Examples of how to use the functions are available.
Installation
pip install academy-tester
Documentation
This module provides two helper classes, OutputTester and ContentTester, designed to be used with Python's unittest framework. OutputTester focuses on running scripts and testing their output, while ContentTester analyzes the source code itself using Abstract Syntax Trees (AST).
Basic test template
import unittest
from academy_tester import OutputTester, ContentTester
class TestPrintStatements(unittest.TestCase):
def setUp(self):
self.OTester = OutputTester(self)
self.CTester = ContentTester(self)
OutputTester
A utility class that wraps a unittest.TestCase to simplify testing the standard output of a Python script. It runs a target script as a subprocess, captures its output and error streams, and provides methods to assert conditions on the results.
__init__(self, testcase, filename="task.py")
Initialises the OutputTester with a unittest.TestCase instance and the name of the file to be tested.
- Args :
testcase( unittest.TestCase ): The test case instance (e.g.,self) from which this class is being used. This is used to call assertion methods likefail().filename( str, optional ): The name of the Python script to be tested. Defaults to"task.py".
test_output(self, output_requirements, input=[], message_addition="")
Runs the target script with specified inputs and asserts that one or more required strings are present in the script's standard output.
- Args :
output_requirements( Union[str, list[str]] ): A single string or a list of strings that must be found in the script's output.input( Iterable[str], optional ): A sequence of strings to be passed to the script's standard input. Defaults to an empty list.message_addition( str, optional ): An additional message to append to the failure message if an assertion fails.- Raises :
AssertionError: If the script produces an error or if any of theoutput_requirementsare not found in the script's output.
test_count(self, expected_output, required_count, input=[])
Runs the script and asserts that a specific string appears a minimum number of times in the output, counting at most one occurrence per line.
- Args :
expected_output( str ): The string to search for in each line of the output.required_count( int ): The minimum number of lines that must contain theexpected_output.input( Iterable[str], optional ): A sequence of strings to be passed to the script's standard input. Defaults to an empty list.- Raises :
AssertionError: If the actual count of lines containing theexpected_outputis less thanrequired_count.
test_line_count(self, input=[])
Runs the script and returns the total number of lines in its standard output.
- Args :
input( Iterable[str], optional ): A sequence of strings to be passed to the script's standard input. Defaults to an empty list.- Returns :
- int : The number of lines produced by the script.
Class ContentTester
A utility class that uses Python's ast (Abstract Syntax Tree) module to statically analyze the source code of a script. This allows for testing code structure, variable assignments, and the use of specific language features without actually executing the script.
__init__(self, testcase, filename="task.py")
Initialises the ContentTester by parsing the target file into an AST.
- Args :
testcase( unittest.TestCase ): The test case instance from which this class is being used.filename( str, optional ): The name of the Python script to be analyzed. Defaults to"task.py".
check_tokens(self, token)
Counts the occurrences of a specific AST token type within the source code. This is useful for checking for operators, boolean logic, etc.
- Args :
token( Type[ast.AST] ): The AST node type to count. For example,ast.Addfor the+operator orast.Forfor a for-loop.- Returns :
- int : The total number of instances of the specified token found in the code.
- Example : Python
# Check how many times the addition operator (+) is used
add_count = content_tester.check_tokens(ast.Add)
get_variables
A property that inspects the AST and returns a dictionary of all variables assigned at the top level of the script.
- Returns :
- dict[str, object] : A dictionary where keys are variable names (str) and values are their corresponding
astvalue nodes.
get_lists
A property that filters the script's variables and returns only the lists, with their constant values extracted.
- Returns :
- dict[str, list] : A dictionary where keys are the names of list variables and values are Python lists containing the constant elements from the source code.
get_function_count(self, function_id)
Counts how many times a function with a specific name is called within the script.
- Args :
function_id( str ): The name of the function to search for (e.g.,"print").- Returns :
- int : The number of times the specified function is called.
get_attribute_count(self, attribute_id)
Counts how many times a specific attribute is accessed on an object (e.g., the .append in my_list.append).
- Args :
attribute_id( str ): The name of the attribute to search for (e.g.,"append").- Returns :
- int : The number of times the specified attribute is accessed.
Metadata
Release files for academy-tester 2.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| academy_tester-2.2.0.tar.gz | 9.1 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| academy_tester-2.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.6 kB
Release files / academy_tester-2.2.0.tar.gz
| Download URL | academy_tester-2.2.0.tar.gz |
|---|---|
| Size | 9.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
38d4d4361f69e9b52401b60fb94ae73ebbbb62904a49a576563927a500d7dc62
|
|
BLAKE2b-256 checksum How to use checksums |
6dee3b85f3f098e94f95e16667178a6b06c3997912e6bbfa7c1113f7efb98ec3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 24, 2025.
Transparency logRelease files / academy_tester-2.2.0-py3-none-any.whl
| Download URL | academy_tester-2.2.0-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0ee788e827ff40299f2201e4b96942683b5f3dfbe5afbc2dd46358bc3299ec3c
|
|
BLAKE2b-256 checksum How to use checksums |
b13ce13109c5ceb8165bce6401d68ca154a76827cc577dcef7a189feb6466a40
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 24, 2025.
Transparency logSecurity for academy-tester 2.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for academy_tester-2.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 24, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.