Skip to content

Commit

Permalink
Merge branch 'master' of github.com:solos/linote
Browse files Browse the repository at this point in the history
  • Loading branch information
solos committed Apr 12, 2014
2 parents a7acbf9 + 7d4e6f9 commit d4b445e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
7 changes: 4 additions & 3 deletions local.py
Expand Up @@ -16,10 +16,11 @@ def gen_filelist():
lndir = '%s/.linote' % os.environ['HOME']
cachefile = '%s/.caches' % lndir
try:
open(cachefile, 'w').write(files)
except:
os.makedirs(lndir)
open(cachefile, 'w').write(files)
except OSError:
if not os.path.exists(lndir):
raise
open(cachefile, 'w').write(files)
return local_files


Expand Down
33 changes: 33 additions & 0 deletions test/test_linote.py
Expand Up @@ -3,6 +3,10 @@

import os
import sys
from utils import clean_style, clean_note
from encoding import (to_unicode,
html_to_unicode,
html_body_declared_encoding)

cur_dir = os.path.abspath(__file__).split('/')[:-2]
par_dir = '/'.join(cur_dir)
Expand All @@ -22,10 +26,39 @@ def tearDown(self):
def test_version(self):
self.assertIsNotNone(linote.__version__, '0.0.1')

def test_utils_clean_style(self):
assert clean_style("hello") == "<p>hello</p>"

def test_utils_clean_note(self):
assert clean_note("<h1>hello</h1>") == "hello"

def test_to_unicode(self):
"""Testing to_unicode function"""
self.assertNotIsInstance("abc", unicode)
self.assertIsInstance(to_unicode("abc", "utf-8"), unicode)

def test_html_to_unicode(self):
"""Testing html_to_unicode function"""
self.assertEqual(
html_to_unicode('charset=("zh_cn")', '<html><h1>漢字汉字</h1></html>'),
('utf8', u'<html><h1>\u6f22\u5b57\u6c49\u5b57</h1></html>'))

def test_html_body_declared_encoding(self):
"""Testing html_body_declared_encoding function"""
self.assertEqual(
html_body_declared_encoding(
'<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-8">'),
'iso8859-8')
self.assertEqual(
html_body_declared_encoding(
'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'),
'utf-8')


def suite():
suite = unittest.TestSuite()
suite.addTest(DefaultTestCase('test_version'))
suite.addTest(DefaultTestCase('test_utils_clean_style'))
return suite


Expand Down

0 comments on commit d4b445e

Please sign in to comment.