Skip to content

Instantly share code, notes, and snippets.

View cgoldberg's full-sized avatar
☠️
¯\_(ツ)_/¯

Corey Goldberg cgoldberg

☠️
¯\_(ツ)_/¯
View GitHub Profile
@cgoldberg
cgoldberg / subunit_save_details.py
Last active August 29, 2015 14:02
subunit - save arbitrary test result details to files
#!/usr/bin/env python3
import logging
import re
from subunit import ByteStreamToStreamResult
from testtools import StreamToExtendedDecorator, TestResult
logging.basicConfig(level='INFO')
@cgoldberg
cgoldberg / testtools_add_details.py
Created July 7, 2014 16:25
testtools - adding test details (content objects) to your tests
#!/usr/bin/env python3
#
# This example adds testtools Details from a testtools TestCase.
#
# For more information about: testtools, Details, and Content Objects, visit:
# * https://testtools.readthedocs.org/en/latest/for-test-authors.html#details
from testtools import TestCase
from testtools.content import (
ContentType,
@cgoldberg
cgoldberg / parse-onloads.py
Created April 9, 2015 18:34
analyze top slowest pages using onload event beacon data
#!/usr/bin/env python
import collections
import re
from operator import itemgetter
import numpy
DATA_FILE = 'perflog-everything-onload.csv'
NUM_RESULTS = 50
@cgoldberg
cgoldberg / mhtest.py
Created April 14, 2015 15:01
parse onload timings and weight with Cochran–Mantel–Haenszel
#!/usr/bin/env python
import collections
import re
from operator import itemgetter
import urlparse
import numpy
import sys
@cgoldberg
cgoldberg / recursive_file_info.py
Created June 20, 2015 10:18
walk a directory tree recursively. print total file count and size.
#!/usr/bin/env python
#
# walk a directory tree recursively.
# print total file count and size.
# Corey Goldberg, 2015
import os
start_dir = '/mnt/wd-green/Tunes'
@cgoldberg
cgoldberg / testing_databases.md
Last active September 28, 2015 18:43
Functional Tests - Database Setup

SQLite as a test database?

One way to create isolate integration tests is to tear down and recreate database tables for every single test. This ensures every test starts with a clean and known state. However, achieving this with MySQL is an expensive (slow) operation and would add too much execution time between tests.

Tracelons uses SQLAlchemy as an ORM. Since the MySQL database is abtracted behind this layer, we could switch test database providers to SQLite. SQLite can be run in-memory, allowing fast teardowns of the test database. Coupled with fast schema creation, this enables very fast database operations during test runs.

However, there are some drawbacks to using SQLite as a replacement for MySQL during testing:

  • Some tooling in the tracelons repo is built specifically for MySQL and would require changes to work with SQLite.
  • SQLite does not have the same features, and does not enforce the same rules as MySQL. Therefore, it differs from production and could possibly allow tests to pass t
@cgoldberg
cgoldberg / test_xvfb_selenium.py
Created November 20, 2012 14:07
headless Selenium WebDriver tests. Python unittest launching browser inside Xvfb.
#!/usr/bin/env python
#
# Corey Goldberg - 2012
#
# requires:
# * Xvfb
# * X Windows
# * xvfbwrapper (pip install xvfbwrapper)
#
@cgoldberg
cgoldberg / test_selenium_xvfb.py
Created November 27, 2012 00:12
Python xvfbwrapper example: Headless Selenium WebDriver Tests
#!/usr/bin/env python
from selenium import webdriver
from xvfbwrapper import Xvfb
import unittest
class TestHomepages(unittest.TestCase):
@cgoldberg
cgoldberg / selenium_xvfb.py
Created November 27, 2012 00:09
Headless Selenium WebDriver with xvfbwrapper
#!/usr/bin/env python
from selenium import webdriver
from xvfbwrapper import Xvfb
# create a virtual display
vdisplay = Xvfb(width=1280, height=720)
vdisplay.start()
# do selenium stuff. look ma, no browser displayed!
@cgoldberg
cgoldberg / pypi_tarball.py
Created December 19, 2012 17:19
Download latest package release from PyPI.
#!/usr/bin/env python
import json
import os
import urllib
"""Download latest source release from PyPI.