#!/usr/bin/python
+import io
import sys
try:
def main(template, data={}, **kwargs):
- with open(template, 'r') as template_file:
+ with io.open(template, 'r', encoding='utf-8') as template_file:
if data != {}:
- data_file = open(data, 'r')
+ data_file = io.open(data, 'r', encoding='utf-8')
data = json.load(data_file)
data_file.close()
# -*- coding: utf-8 -*-
+import io
+
try:
from .tokenizer import tokenize
except (ValueError, SystemError): # python 2
try:
# Maybe it's in the file system
path = partials_path + '/' + name + '.' + partials_ext
- with open(path, 'r') as partial:
+ with io.open(path, 'r', encoding='utf-8') as partial:
return partial.read()
except IOError:
import unittest
import os
import json
+import io
import chevron
+import sys
+if sys.version_info[0] == 3:
+ python3 = True
+else: # python 2
+ python3 = False
+
+
SPECS_PATH = os.path.join('spec', 'specs')
if os.path.exists(SPECS_PATH):
SPECS = [path for path in os.listdir(SPECS_PATH) if path.endswith('.json')]
obj['desc'])
return test_case
- with open(json_path, 'r') as f:
+ with io.open(json_path, 'r', encoding='utf-8') as f:
yaml = json.load(f)
# Generates a unit test for each test object
result = chevron.main('tests/test.mustache', 'tests/data.json',
partials_path='tests')
- with open('tests/test.rendered', 'r') as f:
+ with io.open('tests/test.rendered', 'r', encoding='utf-8') as f:
expected = f.read()
+ if not python3:
+ expected = expected.encode('utf-8')
self.assertEqual(result, expected)