Skip to content

Instantly share code, notes, and snippets.

☠️
¯\_(ツ)_/¯

Corey Goldberg cgoldberg

☠️
¯\_(ツ)_/¯
Block or report user

Report or block cgoldberg

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@cgoldberg
cgoldberg / subunit_save_details.py
Last active Aug 29, 2015
subunit - save arbitrary test result details to files
View subunit_save_details.py
#!/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 Jul 7, 2014
testtools - adding test details (content objects) to your tests
View testtools_add_details.py
#!/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 Apr 9, 2015
analyze top slowest pages using onload event beacon data
View parse-onloads.py
#!/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 Apr 14, 2015
parse onload timings and weight with Cochran–Mantel–Haenszel
View mhtest.py
#!/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 Jun 20, 2015
walk a directory tree recursively. print total file count and size.
View recursive_file_info.py
#!/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 Sep 28, 2015
Functional Tests - Database Setup
View testing_databases.md

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 Nov 20, 2012
headless Selenium WebDriver tests. Python unittest launching browser inside Xvfb.
View test_xvfb_selenium.py
#!/usr/bin/env python
#
# Corey Goldberg - 2012
#
# requires:
# * Xvfb
# * X Windows
# * xvfbwrapper (pip install xvfbwrapper)
#
@cgoldberg
cgoldberg / test_selenium_xvfb.py
Created Nov 27, 2012
Python xvfbwrapper example: Headless Selenium WebDriver Tests
View test_selenium_xvfb.py
#!/usr/bin/env python
from selenium import webdriver
from xvfbwrapper import Xvfb
import unittest
class TestHomepages(unittest.TestCase):
@cgoldberg
cgoldberg / selenium_xvfb.py
Created Nov 27, 2012
Headless Selenium WebDriver with xvfbwrapper
View selenium_xvfb.py
#!/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 Dec 19, 2012
Download latest package release from PyPI.
View pypi_tarball.py
#!/usr/bin/env python
import json
import os
import urllib
"""Download latest source release from PyPI.
You can’t perform that action at this time.