Skip to main content

codetest

A simple python library which makes it easier to test code after solving a coding problem.

How to Install

codetest can be installed using pip install codetest.

  • required
    • Python 3.6.0+

pip install codetest

How to Use

To run a test, you need to pass an array of tests and the class in which the function is written

from codetest import CodeTest

class AnyName:
    def AnyNameFn(self,...AnyNumberOfInputs):
        return result

tests = [
    {},
    ...
]

# Call to the Test Library
CodeTest(tests,AnyName)

How to write a testcase?

#index.py
from codetest import CodeTest
class Problem:
    def sumOfTwoNumbers(self, a=2,b=2):
        return a + b
    def main(self, a=2,b=2):
        return a - b

tests = [
    #Test 0
    {
        "function" : "sumOfTwoNumbers",
        "params" : {
            "input":[
                {"value":5},
                {"value":4},
            ],
            "output":[{"value":8}]
        }
    },
    #Test 1
    {
        "function" : "sumOfTwoNumbers",
        "params" : {
            #input not passed hence the function either takes default values or doesn't expect any inputs
            "output":[{"value":8}]
        }
    },
    #Test 2
    {
        # if function is not passed then `main` is executed
        "params" : {
            #input not passed hence the function either takes default values or doesn't expect any inputs
            "output":[{"value":8}]
        }
    },
]

CodeTest(tests,Problem)
  • This will result in following output
--------------------------[TEST 0]--------------------------
Expected Output: 8
Computed Output: 9
                                             [Time: 0.001ms]
------------------------------------------------------------
--------------------------[TEST 1]--------------------------
Expected Output: 8
Computed Output: 4
                                             [Time: 0.001ms]
------------------------------------------------------------
--------------------------[TEST 2]--------------------------
Expected Output: 8
Computed Output: 0
                                             [Time: 0.001ms]
------------------------------------------------------------

Tests

Testcase Structure

? - Optional

    tests = [
        {
            function?: "" // default "main"
            params?: {
                input?:[],
                output?:[]
            }
        }
    ]
  • If function is not provided, the default function would be main
  • The order in which the input objects are added would be same as the params passed to the function.
  • if input is not passed, then it is considered same as no inputs passed to the function
  • if output is not passed, then the test doesn't expect any output to be returned from the function.
  • if params is not passed, then the function is executed as-is with no input and output

Input/Output Structure

? - Optional

    {
        value: any,
        type?: any,
    }

Supported Types

  1. int
  2. float
  3. list
  4. tuple
  5. dict
  6. set
  7. bool
  8. linkedlist
  9. binarytree

Metadata

Release files for codetest 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for codetest 1.1.0
File Size Uploaded Provenance
codetest-1.1.0.tar.gz 8.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for codetest 1.1.0
File Interpreter ABI Platform
codetest-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.2 kB

Release files / codetest-1.1.0.tar.gz

Download URL codetest-1.1.0.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d47f7d25c5ddfef00474957e8f53784263385288a9778f62d4811418000c57d5
BLAKE2b-256 checksum
How to use checksums
f9dd050b91b18660d644604f3593f4713aa5036d3b73f90e736544e9ff6c03b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1

Release files / codetest-1.1.0-py3-none-any.whl

Download URL codetest-1.1.0-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0f0c3046ddc9aee626f3a24bee0d1b98a115a71d046b2d5b09adb1f5d8fc6f49
BLAKE2b-256 checksum
How to use checksums
8e5569025b357606788d63c5ecff6ccf39e9b6520059768bdbba031254d4b648
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1

Security for codetest 1.1.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page