Skip to content

Instantly share code, notes, and snippets.

View nicoddemus's full-sized avatar

Bruno Oliveira nicoddemus

View GitHub Profile
@nicoddemus
nicoddemus / oitavas.txt
Last active April 5, 2021 20:42
Soccer score generator
Seed: 173015
0 X 1
1 X 1
0 X 2
1 X 1
2 X 1
1 X 1
1 X 3
2 X 2
@nicoddemus
nicoddemus / runtests.py
Last active August 29, 2015 14:04
How to embed `pytest.main` into a frozen executable created by cx_freeze
import pytest, sys
sys.exit(pytest.main())
@nicoddemus
nicoddemus / README.md
Last active April 15, 2022 19:23
Example on how to structure a package and testing modules

Arrange files like this:

apple/
  __init__.py
  apple.py
tests/
  test_everything.py
@nicoddemus
nicoddemus / conftest.py
Created March 14, 2015 13:22
Expect conftest with small modification
# original from: http://pythontesting.net/framework/pytest/pytest-expect-plugin-1
import pytest
import inspect
import os.path
@pytest.fixture
def expect(request):
def do_expect(expr, msg=''):
if not expr:
_log_failure(request.node, msg)
@nicoddemus
nicoddemus / image_diff.py
Created March 25, 2015 23:18
Image diff fixture (draft)
from PIL import ImageChops, ImageDraw, Image
import pytest
import os
import py.path
import math
import operator
def rms_diff(im1, im2):
"""Calculate the root-mean-square difference between two images
Taken from: http://snipplr.com/view/757/compare-two-pil-images-in-python/
@nicoddemus
nicoddemus / gist:d30c616122e30c938b6b
Created April 27, 2015 17:08
Test instance deletion (pytest runner, both pytest style class and xUnit)
from __future__ import unicode_literals
import weakref
from coilib50 import unittest
class Test(unittest.TestCase):
_TESTS = []
def test_01(self):
Test._TESTS.append(weakref.ref(self))
@nicoddemus
nicoddemus / cx_freeze_and_distutils.md
Created May 19, 2015 17:45
Problem trying to freeze an executable which imports distutils modules (directly or indirectly)

cxFreeze and distutils

Problem

When trying to freeze a script which imports any distutils module (for example, distutils.dist), the script fails at runtime with an exception like this:

>   from distutils import dist, sysconfig
E   ImportError: cannot import name dist
@nicoddemus
nicoddemus / ren_pytest_prefix.py
Last active August 29, 2015 14:22
Rename all tests from "pytest_" to "test_", including data directories
import os
import fnmatch
import sys
directory = sys.argv[1]
for root, dirs, names in os.walk(sys.argv[1]):
for name in names:
if fnmatch.fnmatch(name, 'pytest_*.py') and os.path.basename(root) == '_tests':
source = os.path.join(root, name)
@nicoddemus
nicoddemus / close_issues.py
Created June 16, 2015 21:00
Close bitbucket issues for pytest repository, after migrating to GitHub
import requests
auth = ('nicoddemus', 'XXXX')
for issue_id in xrange(1, 768+1):
url = 'https://bitbucket.org/api/1.0/repositories/{accountname}/{repo_slug}/issues/{issue_id}/comments'
url = url.format(accountname='pytest-dev', repo_slug='pytest', issue_id=issue_id)
print '-' *10, issue_id
data = {
"content": "This issue has been moved to GitHub: https://github.com/pytest-dev/pytest/issues/{issue_id}".format(issue_id=issue_id),
}
@nicoddemus
nicoddemus / conftest.py
Created September 29, 2015 22:50
load_tests example fixed
import types
import unittest
from _pytest.unittest import TestCaseFunction
import pytest
class LoadTestsSuiteCollector(pytest.Collector):
def __init__(self, name, parent, suite):