Skip to content

Instantly share code, notes, and snippets.

View itsmemattchung's full-sized avatar

Matt Chung itsmemattchung

View GitHub Profile
@itsmemattchung
itsmemattchung / mocking_tempfile.py
Created January 30, 2016 09:27
Example on mocking a tempfile
import tempfile
import mock
def use_tempfile():
dest_dir = '/tmp'
with tempfile.NamedTemporaryFile(dir=dest_dir, delete=False) as temp_dest:
print "hello world"
return temp_dest
@mock.patch.object(tempfile, 'NamedTemporaryFile')
def call_use_tempfile(temp_file):
@itsmemattchung
itsmemattchung / wc
Created January 22, 2016 13:51
Home stretch
(github3)Matts-Air:github3.py mattchung$ wc -l tests/*.py | sort
0 tests/__init__.py
17 tests/nbtest.py
17 tests/test_github.py
22 tests/fixtures.py
44 tests/conftest.py
79 tests/test_structs.py
127 tests/utils.py
430 tests/test_repos.py
736 total
[program:uwsgi-{{ project }}-{{ env }}]
command={% if new_relic_enabled %}{{ env_folder }}/bin/newrelic-admin run-program {% endif %}{{ env_folder }}/bin/uwsgi --ini {{ env_folder }}/uwsgi.ini
autostart=true
startsecs=10
stopwaitsecs=35
redirect_stderr=true
stopsignal=QUIT
environment=CELERY_LOADER='django',DJANGO_SETTINGS_CHAIN='www',NEW_RELIC_CONFIG_FILE='/etc/newrelic/new-relic-{{ project }}-{{ env }}-www.ini'
stdout_logfile=/var/log/supervisor/uwsgi-{{ project }}-{{ env }}.log
stderr_logfile=/var/log/supervisor/uwsgi-{{ project }}-{{ env }}-stderr.log
@itsmemattchung
itsmemattchung / licenses.py
Created December 3, 2015 08:27
License __dict__ update
# -*- coding: utf-8 -*-
"""
github3.licenses
================
This module contains the classes relating to licenses
See also: https://developer.github.com/v3/licenses/
"""
from __future__ import unicode_literals
@itsmemattchung
itsmemattchung / subclass_example.py
Created November 25, 2015 16:13
how to make mistakes in python subclass
class MyOtherClass(object):
def do_something(self):
self.__do_a_new_step()
self.__do_one_more_step()
# Should be subclassing from MyClass
class MyOtherClass(MyClass):
def do_something(self):
self.__do_a_new_step()
self.__do_one_more_step()
/**
* Sumologic module
* @module lib/sumologic
*/
var rsvp = require('rsvp');
var fs = require('fs');
var request = require('request')
var util = require('util');
@itsmemattchung
itsmemattchung / gist:822577fa9477d33b6fa8
Created October 8, 2015 18:05
Github3 tests failing
(github3)Matts-MacBook-Air:github3.py mattchung$ make tests >> /tmp/github3_errors.txt
no previously-included directories found matching '*.pyc'
no previously-included directories found matching 'docs/_build'
make: *** [travis] Error 1
(github3)Matts-MacBook-Air:github3.py mattchung$ view /tmp/github3_errors.txt
Processing /Users/mattchung/Development/github3.py
Requirement already satisfied (use --upgrade to upgrade): github3.py==1.0.0a2 from file:///Users/mattchung/Development/github3.py in /Users/mattchung/.virtualenvs/github3/lib/python2.7/site-packages (from -r dev-requirements.txt (line 1))
Requirement already satisfied (use --upgrade to upgrade): mock==1.0.1 in /Users/mattchung/.virtualenvs/github3/lib/python2.7/site-packages (from -r dev-requirements.txt (line 2))
Requirement already satisfied (use --upgrade to upgrade): pytest>=2.3.5 in /Users/mattchung/.virtualenvs/github3/lib/python2.7/site-packages (from -r dev-requirements.txt (line 3))
openstack output will be in this color.
==> openstack: Creating temporary keypair for this instance...
==> openstack: Waiting for server (f8fc5320-019b-44f7-91da-98104571fc60) to become ready...
==> openstack: Waiting for SSH to become available...
==> openstack: Connected to SSH!
==> openstack: Provisioning with Ansible...
openstack: Creating Ansible staging directory...
openstack: Creating directory: /tmp/packer-provisioner-ansible-local
openstack:
@itsmemattchung
itsmemattchung / gist:36f619efe8cf9c0a7a1d
Created April 1, 2015 21:44
why would you have a nested function with mock in there?
1064 class TestTokenize(TestCase):
1065
1066 def test_tokenize(self):
1067 import tokenize as tokenize_module
1068 encoding = object()
1069 encoding_used = None
1070 def mock_detect_encoding(readline):
1071 return encoding, [b'first', b'second']
1072
diff --git a/Lib/tokenize.py b/Lib/tokenize.py
index 8bc83fd..96edf6c 100644
--- a/Lib/tokenize.py
+++ b/Lib/tokenize.py
@@ -434,12 +434,16 @@ def open(filename):
"""Open a file in read only mode using the encoding detected by
detect_encoding().
"""
- buffer = _builtin_open(filename, 'rb')
- encoding, lines = detect_encoding(buffer.readline)