Skip to main content

ExploTest

Project description

Some assumptions on the transformer and how to fix your code:

  1. Generally, no global states. As the transformer essentially runs your input again, for any sequence of inputs, it is assumed that the result running the sequence twice will be the same. This means that global states that may change during
    testing is not testable. This also means singleton patterns are more or less untestable. Pass the mechanism in as a class instead.

To fix:

Before:

node_id = 0

def get_new_id() -> int:
    global node_id
    node_id += 1
    return node_id


class Foo:
    def __init__(self):
        self.node_id = get_new_id()


if __name__ == "__main__":   # When testing
    assert Foo().node_id == 1

After:

class IDGenerator:
    def __init__(self):
        self.node_id = 0
        
        
    def get_next_id(self) -> int:
        self.node_id += 1
        return self.node_id


class Foo:
    def __init__(self, id_gen: IDGenerator):
        self.node_id = id_gen.get_next_id()

if __name__ == "__main__":  # When testing
    id_generator = IDGenerator()
    assert Foo(id_generator).node_id == 1

or

class IDGenerator:
    def __init__(self):
        self.node_id = 0


    def get_new_id(self) -> int:
        self.node_id += 1
        return self.node_id

id_generator: IDGenerator = None

def get_next_id():
    if id_generator is None:
        raise Exception()  # Can also return some default value
    return id_generator.get_new_id()

def set_id_generator(id_gen: IDGenerator):
    global id_generator
    id_generator = id_gen
    
class Foo:
    def __init__(self):
        self.node_id = get_next_id()
        
if __name__ == "__main__":  # When testing
    set_id_generator(IDGenerator())
    assert Foo().node_id == 1
  1. (If using the print exploration function):
    • A single point of return, situated at the bottom of the file
    • The state is not changed after the print
    • A returned value (if tuples) is a subset of exploratory print expression
    • The test generated is not super robust; specifically the test generated might not cover the entire list if the iterator loops through all the items (the index isn't retrievable)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

explotest-0.1.4.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ExploTest-0.1.4-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file explotest-0.1.4.tar.gz.

File metadata

  • Download URL: explotest-0.1.4.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.4

File hashes

Hashes for explotest-0.1.4.tar.gz
Algorithm Hash digest
SHA256 221f6b064b24d9dd10d20dd5256559377529c13df5e40b18e459b6ed85c35c4a
MD5 7611699477ab2ad6e56e18f5e4f2fcf6
BLAKE2b-256 1d51e9686eea29af9f77edf3069eb28019a68d4402abb9cc0e6ba81c10c192c8

See more details on using hashes here.

File details

Details for the file ExploTest-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: ExploTest-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.4

File hashes

Hashes for ExploTest-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4a4d1bc9d5ccd971d07bea43c8d1a3bb7b9f0945a8085fcc24e529f02e466917
MD5 bd70b590dff3498253f2dd865530ffc2
BLAKE2b-256 89e250b37f69640f17a5d8cf28d3104ab338da2dfe8404eb170270086b24a11b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page