Skip to main content

# Chara

Chara enables developers to quickly create characterization tests. Start by creating integration tests using whatever testing framework you prefer. Using Chara you decorate those test functions to record interactions with specific dependencies. Afterwards, you can replay the recording and those dependencies will behave as recorded.

## Usage

Create production code and passing integration test (test_scraper.py):

def scrape_headline(name):
    url, search = {
        'wired': (
            'http://www.wired.com',
            '<div class="headline headline1">\s*'
            '<h5>[^<]*</h5>\s*'
            '<h2>\s*<a[^>]*>([^<]*?)</a>\s*</h2>\s*'
            '</div>'
        )
    }[name]

    matches = re.search(search, get_html(url))

    return matches.group(1) if matches else None


def get_html(url):
    return urllib2.urlopen(url).read()


class DemoTest(TestCase):
    def test_scraper(self):
        self.assertEqual(
            'This Is What Happens When You Hack and '
            'Extort the \'Bitcoin Jesus\'',
            scrape_headline('wired')
        )

Add chara.record decorator and run the test:

class DemoTest(TestCase):
    @chara.record('test_scraper.get_html')
    def test_scraper(self):
        self.assertEqual(
            'This Is What Happens When You Hack and '
            'Extort the \'Bitcoin Jesus\'',
            scrape_headline('wired')
        )

Switch to using chara.replay and notice that even if you turn get_html() to a no-op function the test still passes, so you know that the function’s normal functionality is being bypassed by Chara’s replay functionality.:

def get_html(url):
    pass # nothing even happening here, but the test passes!

class DemoTest(TestCase):
    @chara.replay('test_scraper.get_html')
    def test_scraper(self):
        self.assertEqual(
            'This Is What Happens When You Hack and '
            'Extort the \'Bitcoin Jesus\'',
            scrape_headline('wired')
        )

## License

Uses the [MIT](http://opensource.org/licenses/MIT) license.

Metadata

Release files for chara 0.1.5

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

Source distribution (sdist)

Source distribution for chara 0.1.5
File Size Uploaded Provenance Actions
chara-0.1.5.tar.gz 7.7 kB Without provenance Details for chara-0.1.5.tar.gz

Release files / chara-0.1.5.tar.gz

Download URL chara-0.1.5.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
37b687d5e5e5a51ab4087f9c52d2c9dc5fd6efb47b0e49f5d678bc7a715ee9ef
BLAKE2b-256 checksum
How to use checksums
998a017bf32e4864ed6d9bb585cc8e98554d70f87272644c27b4e6a8eca157ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for chara 0.1.5

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

0.1.5 This release

1 release file 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