---
# System prepended metadata

title: Maintenance Programming
tags: [skola, ' maintenance programming']

---

---
tags: skola, maintenance programming
---
# Maintenance Programming
## Adding a test for a builtin-function

Adding a test, specifically a test for one of pythons builtin-functions, can be done by following the steps below.

1. Check if a stub of a test file for the function you want to test the already exists. I'll be under `tests/builtin/test_<function>.py`. If not, create it.
2. The file should be of the same format as the other builtin function tests.
   In the example below `<function>` should be replaced with the name of the function to test.
   
   ```python
   from .. utils import TranspileTestCase, BuiltinFunctionTestCase
   
   class <Function>Tests:
       def test_<function>_str(self):
           self.assertCodeExecution("""
               print(<function>(...))
               """)
       
   class Builtin<Function>FunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
       functions = ["<function>"]
       
       not_implemented = [
           'test_bool',
           'test_bytearray',
           'test_bytes',
           'test_class',
           'test_complex',
           'test_dict',
           'test_float',
           'test_frozenset',
           'test_int',
           'test_list',
           'test_none',
           'test_notimplemented',
           'test_range',
           'test_set',
           'test_slice',
           'test_str',
           'test_tuple',
           'test_obj',
       ]
   ```
3. Add tests named `test_<function>_<type/use_case>` where each test tests a different data type or use case of the function. The util function `assertCodeExecution` compares the output of the same code run using native *python* and using *java* transpiled using *voc*. Other util test functions may also be used if it is required but `assertCodeExecution` should be sufficient for most tests.

    The variable `functions` in `Builtin<Function>FunctionTests` contains a list of builtin functions that are automatically tested using a list of default tests. Unless the function you want to test is not a typical case where it should simply be tested using various data types, this should contain a single entry containing the name of the function to test.
    
    By default, `not_implemented` contains a list of the default tests that should be ignored, i.e. not count as hard fails if or when they fail. It may be useful to look through the list `SAMPLE_DATA` in `tests/utils.py` to check if the provided tests are sufficient to test the function. If so, simply remove that test from `not_implemented`, otherwise write your own test in the class `<Function>Tests`. Examples where this is needed is edge cases your function may have or the need to test certain nested data types. If your function does not need to be tested using different data than what the default tests provide you should simply remove everything from `not_implemented` and leave `<Function>Tests` empty.