This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Unescape HTML junk into something readable | |
Usage: python html_unescape.py < input_file | |
""" | |
import fileinput | |
import HTMLParser | |
replacements = [ | |
('\\:', ':') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
import unittest | |
def unordered_list_diff(list1, list2): | |
""" Disregard of items order, compare two lists. | |
:param list1: List to compare | |
:param list2: List to compare | |
:return: None if the lists are identical, or a tuple of 3: | |
Items only in list 1 or None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Demo the use of longMessage to give more details """ | |
import unittest | |
class MyTestCase(unittest.TestCase): | |
def test_use_long_message(self): | |
""" Use longMessage for more detailed error message """ | |
self.longMessage = True | |
actual_values = [0, 1, 2, 3] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Use of class for generic test data """ | |
import unittest | |
from ddt import ddt, data | |
class TestData(object): | |
def __init__(self, name, **kwargs): | |
self._name = name | |
for k, v in kwargs.iteritems(): | |
setattr(self, k, v) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
INFO = logging.INFO | |
DEBUG = logging.DEBUG | |
WARNING = logging.WARNING | |
def create_logger(logger_name, log_level=logging.WARNING, filename=None): | |
""" Create a logger that log to the console, if a filename is | |
supplied, log to that file as well. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import collections | |
json_string = """ | |
{ | |
"a": 1, | |
"a": 2, | |
"b": [1,2,3], | |
"b": "foo", | |
"c": {"x":1, "y":2, "z":3, "a":4} |
NewerOlder