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.
Project description
# 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file chara-0.1.5.tar.gz
.
File metadata
- Download URL: chara-0.1.5.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37b687d5e5e5a51ab4087f9c52d2c9dc5fd6efb47b0e49f5d678bc7a715ee9ef |
|
MD5 | b4b325a75a6821c26902ae87fd319bc0 |
|
BLAKE2b-256 | 998a017bf32e4864ed6d9bb585cc8e98554d70f87272644c27b4e6a8eca157ab |