From 88c823a2e086a68fb7702ce0139cfde721f29a5b 2011-03-24 19:35:37 From: Thomas Kluyver Date: 2011-03-24 19:35:37 Subject: [PATCH] Moved unicode tests into main test suite. Reverified that both fail if the fixes in previous commits are undone. --- diff --git a/IPython/core/tests/test_compilerop.py b/IPython/core/tests/test_compilerop.py index 3d133ae..26ed154 100644 --- a/IPython/core/tests/test_compilerop.py +++ b/IPython/core/tests/test_compilerop.py @@ -46,6 +46,14 @@ def test_compiler(): cp('x=1', 'single') nt.assert_true(len(linecache.cache) > ncache) +def test_compiler_unicode(): + import sys + nt.assert_equal(sys.getdefaultencoding(), "ascii") + + cp = compilerop.CachingCompiler() + ncache = len(linecache.cache) + cp(u"t = 'žćčšđ'", "single") + nt.assert_true(len(linecache.cache) > ncache) def test_compiler_check_cache(): """Test the compiler properly manages the cache. diff --git a/IPython/core/tests/test_history.py b/IPython/core/tests/test_history.py index dc440f5..84a6a3a 100644 --- a/IPython/core/tests/test_history.py +++ b/IPython/core/tests/test_history.py @@ -17,7 +17,7 @@ from IPython.utils.tempdir import TemporaryDirectory from IPython.core.history import HistoryManager, extract_hist_ranges def test_history(): - + nt.assert_equal(sys.getdefaultencoding(), "ascii") ip = get_ipython() with TemporaryDirectory() as tmpdir: #tmpdir = '/software/temp' @@ -32,7 +32,7 @@ def test_history(): ip.history_manager.init_db() # Has to be called after changing file ip.history_manager.reset() print 'test',histfile - hist = ['a=1', 'def f():\n test = 1\n return test', 'b=2'] + hist = ['a=1', 'def f():\n test = 1\n return test', u'b="žćčšđ"'] for i, h in enumerate(hist, start=1): ip.history_manager.store_inputs(i, h) @@ -92,6 +92,7 @@ def test_history(): # Restore history manager ip.history_manager = hist_manager_ori + def test_extract_hist_ranges(): instr = "1 2/3 ~4/5-6 ~4/7-~4/9 ~9/2-~7/5" expected = [(0, 1, 2), # 0 == current session diff --git a/tools/unicode_tests.py b/tools/unicode_tests.py deleted file mode 100644 index dfbe7fb..0000000 --- a/tools/unicode_tests.py +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 -"""These tests have to be run separately from the main test suite (iptest), -because that sets the default encoding to utf-8, and it cannot be changed after -the interpreter is up and running. The default encoding in a Python 2.x -environment is ASCII.""" -import unittest -import sys, os.path - -from IPython.core import ipapi -from IPython.core import compilerop -from IPython.core.history import HistoryManager -from IPython.utils.tempdir import TemporaryDirectory - -assert sys.getdefaultencoding() == "ascii" - -class CompileropTest(unittest.TestCase): - def test_accept_unicode(self): - cp = compilerop.CachingCompiler() - cp(u"t = 'žćčšđ'", "single") - -class HistoryTest(unittest.TestCase): - def test_reload_unicode(self): - ip = ipapi.get() - with TemporaryDirectory() as tmpdir: - histfile = os.path.realpath(os.path.join(tmpdir, 'history.json')) - # Ensure that we restore the history management that we mess with in - # this test doesn't affect the IPython instance used by the test - # suite beyond this test. - hist_manager_ori = ip.history_manager - try: - ip.history_manager = HistoryManager(ip) - ip.history_manager.hist_file = histfile - print 'test',histfile - hist = [u"t = 'žćčšđ'"] - # test save and load - ip.history_manager.input_hist_raw[:] = [] - for h in hist: - ip.history_manager.input_hist_raw.append(h) - ip.save_history() - ip.history_manager.input_hist_raw[:] = [] - ip.reload_history() - self.assertEqual(len(ip.history_manager.input_hist_raw), len(hist)) - for i,h in enumerate(hist): - self.assertEqual(hist[i], ip.history_manager.input_hist_raw[i]) - finally: - # Restore history manager - ip.history_manager = hist_manager_ori - -if __name__ == "__main__": - unittest.main()