# Path: ejtp/util/hasher.py
# HASH_FUNCTION = 'sha1' # was md5
# def make(string):
# def make6(string):
# def maken(string, n):
# def strict(obj=None):
# def strictify(jsonstring):
# def checksum(obj):
# 
# Path: ejtp/util/crashnicely.py
# class Guard(object):
# 	'''
# 	Class of exception catching and printing objects.
# 
# 	>>> with Guard():
# 	...     print("This code is okay")
# 	This code is okay
# 	>>> with Guard(print_traceback=False):
# 	... 	print("This code is bad"[""]) # doctest: +ELLIPSIS
# 	Traceback <traceback object at ...> caught by <ejtp.util.crashnicely.Guard object at ...>
# 	'''
# 	def __init__(self, print_catch=True, print_traceback=True):
# 		# Workaround for doctest being dumb, will fix better later
# 		self.print_catch = print_catch 
# 		self.print_traceback = print_traceback
# 
# 	def __enter__(self):
# 		pass
# 
# 	def __exit__(self, exc_type, exc_value, exc_traceback):
# 		if not exc_traceback:
# 			return True
# 		if self.print_catch:
# 			print("Traceback %s caught by %s" % (exc_traceback, self))
# 		if self.print_traceback:
# 			traceback.print_exception(exc_type, exc_value, exc_traceback)
# 		return True
# 
# Path: ejtp/util/compat.py



import sys
import json
from persei import RawData, String
from ejtp.util import hasher
from ejtp.util.crashnicely import Guard
from ejtp.util.compat import unittest, StringIO


class TestHasherStrictify(unittest.TestCase):

    def _assert(self, expected, value):
        value = hasher.strictify(json.dumps(value))
        self.assertEqual(RawData(expected), RawData(value))

    def test_bool(self):
        self._assert('false', False)

    def test_none(self):
        self._assert('null', None)

    def test_string(self):
        self._assert('"test"', 'test')

    def test_int(self):
        self._assert('1', 1)

    def test_list(self):
        self._assert('["test1","test2"]', ['test1', 'test2'])

    def test_tuple(self):
        self._assert('["test1","test2"]', ('test1', 'test2'))

    def test_dict(self):
        self._assert('{"test1":1,"test2":2}', {'test1': 1, 'test2': 2})



# Path: ejtp/util/hasher.py
# HASH_FUNCTION = 'sha1' # was md5
# def make(string):
# def make6(string):
# def maken(string, n):
# def strict(obj=None):
# def strictify(jsonstring):
# def checksum(obj):
# 
# Path: ejtp/util/crashnicely.py
# class Guard(object):
# 	'''
# 	Class of exception catching and printing objects.
# 
# 	>>> with Guard():
# 	...     print("This code is okay")
# 	This code is okay
# 	>>> with Guard(print_traceback=False):
# 	... 	print("This code is bad"[""]) # doctest: +ELLIPSIS
# 	Traceback <traceback object at ...> caught by <ejtp.util.crashnicely.Guard object at ...>
# 	'''
# 	def __init__(self, print_catch=True, print_traceback=True):
# 		# Workaround for doctest being dumb, will fix better later
# 		self.print_catch = print_catch 
# 		self.print_traceback = print_traceback
# 
# 	def __enter__(self):
# 		pass
# 
# 	def __exit__(self, exc_type, exc_value, exc_traceback):
# 		if not exc_traceback:
# 			return True
# 		if self.print_catch:
# 			print("Traceback %s caught by %s" % (exc_traceback, self))
# 		if self.print_traceback:
# 			traceback.print_exception(exc_type, exc_value, exc_traceback)
# 		return True
# 
# Path: ejtp/util/compat.py



# Path: ejtp/tests/test_util.py
import sys
import json
from persei import RawData, String
from ejtp.util import hasher
from ejtp.util.crashnicely import Guard
from ejtp.util.compat import unittest, StringIO



class TestHasherStrictify(unittest.TestCase):

    def _assert(self, expected, value):
        value = hasher.strictify(json.dumps(value))
        self.assertEqual(RawData(expected), RawData(value))

    def test_bool(self):
        self._assert('false', False)

    def test_none(self):
        self._assert('null', None)

    def test_string(self):
        self._assert('"test"', 'test')

    def test_int(self):
        self._assert('1', 1)

    def test_list(self):
        self._assert('["test1","test2"]', ['test1', 'test2'])

    def test_tuple(self):
        self._assert('["test1","test2"]', ('test1', 'test2'))

    def test_dict(self):
        self._assert('{"test1":1,"test2":2}', {'test1': 1, 'test2': 2})



class TestHasherChecksum(unittest.TestCase):