- [bug] Cleaned up all the various deprecation/
  file warnings when running the tests under
  various Pythons with warnings turned on.
  [ticket:213]
diff --git a/CHANGES b/CHANGES
index e916eb8..abd1f80 100644
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,11 @@
 - [bug] Fixed bug where mako-render script wasn't
   compatible with Py3k.  [ticket:212]
 
+- [bug] Cleaned up all the various deprecation/
+  file warnings when running the tests under
+  various Pythons with warnings turned on.
+  [ticket:213]
+
 0.8.0
 - [feature] Performance improvement to the
   "legacy" HTML escape feature, used for XML
diff --git a/mako/compat.py b/mako/compat.py
index 2dba143..3a4742d 100644
--- a/mako/compat.py
+++ b/mako/compat.py
@@ -2,7 +2,7 @@
 import time
 
 py3k = sys.version_info >= (3, 0)
-py3kwarning = getattr(sys, 'py3kwarning', False) or py3k
+py33 = sys.version_info >= (3, 3)
 py26 = sys.version_info >= (2, 6)
 py25 = sys.version_info >= (2, 5)
 jython = sys.platform.startswith('java')
@@ -42,6 +42,21 @@
     def octal(lit):
         return eval("0" + lit)
 
+
+if py33:
+    from importlib import machinery
+    def load_module(module_id, path):
+        return machinery.SourceFileLoader(module_id, path).load_module()
+else:
+    import imp
+    def load_module(module_id, path):
+        fp = open(path, 'rb')
+        try:
+            return imp.load_source(module_id, path, fp)
+        finally:
+            fp.close()
+
+
 def exception_as():
     return sys.exc_info()[1]
 
@@ -120,7 +135,7 @@
     def inspect_func_args(fn):
         return inspect.getargspec(fn)
 
-if py3kwarning:
+if py3k:
     def callable(fn):
         return hasattr(fn, '__call__')
 else:
@@ -135,4 +150,3 @@
     return meta("%sBase" % meta.__name__, (base,), {})
 ################################################
 
-
diff --git a/mako/template.py b/mako/template.py
index 9c64987..412b27c 100644
--- a/mako/template.py
+++ b/mako/template.py
@@ -376,7 +376,7 @@
                             filename,
                             path,
                             self.module_writer)
-            module = util.load_module(self.module_id, path)
+            module = compat.load_module(self.module_id, path)
             del sys.modules[self.module_id]
             if module._magic_number != codegen.MAGIC_NUMBER:
                 data = util.read_file(filename)
@@ -386,7 +386,7 @@
                             filename,
                             path,
                             self.module_writer)
-                module = util.load_module(self.module_id, path)
+                module = compat.load_module(self.module_id, path)
                 del sys.modules[self.module_id]
             ModuleInfo(module, path, self, filename, None, None)
         else:
diff --git a/mako/util.py b/mako/util.py
index 87be71b..c0e1968 100644
--- a/mako/util.py
+++ b/mako/util.py
@@ -4,7 +4,6 @@
 # This module is part of Mako and is released under
 # the MIT License: http://www.opensource.org/licenses/mit-license.php
 
-import imp
 import re
 import collections
 import codecs
@@ -364,9 +363,3 @@
     finally:
         fp.close()
 
-def load_module(module_id, path):
-    fp = open(path, 'rb')
-    try:
-        return imp.load_source(module_id, path, fp)
-    finally:
-        fp.close()
diff --git a/test/test_lexer.py b/test/test_lexer.py
index 0b1c210..3076de4 100644
--- a/test/test_lexer.py
+++ b/test/test_lexer.py
@@ -774,7 +774,7 @@
                       ControlLine('if', 'endif #end', True, (6, 1))]))
 
     def test_crlf(self):
-        template = open(self._file_path("crlf.html"), 'rb').read()
+        template = util.read_file(self._file_path("crlf.html"))
         nodes = Lexer(template).parse()
         self._compare(
             nodes,
diff --git a/test/test_lru.py b/test/test_lru.py
index cde5601..6152799 100644
--- a/test/test_lru.py
+++ b/test/test_lru.py
@@ -23,12 +23,12 @@
             l[id] = item(id)
 
         # first couple of items should be gone
-        self.assert_(1 not in l)
-        self.assert_(2 not in l)
+        assert 1 not in l
+        assert 2 not in l
 
         # next batch over the threshold of 10 should be present
         for id in range(11,20):
-            self.assert_(id in l)
+            assert id in l
 
         l[12]
         l[15]
@@ -38,11 +38,11 @@
         l[26] = item(26)
         l[27] = item(27)
 
-        self.assert_(11 not in l)
-        self.assert_(13 not in l)
+        assert 11 not in l
+        assert 13 not in l
 
         for id in (25, 24, 23, 14, 12, 19, 18, 17, 16, 15):
-            self.assert_(id in l)
+            assert id in l
 
     def _disabled_test_threaded(self):
         size = 100
diff --git a/test/test_template.py b/test/test_template.py
index 25b2fae..28db06d 100644
--- a/test/test_template.py
+++ b/test/test_template.py
@@ -5,6 +5,7 @@
 from mako.ext.preprocessors import convert_comments
 from mako import exceptions, runtime
 from mako import compat
+from mako import util
 import os
 from test.util import flatten_result, result_lines
 from mako.compat import u
@@ -219,7 +220,7 @@
         )
 
         self._do_memory_test(
-            open(self._file_path("unicode_arguments.html"), 'rb').read(),
+            util.read_file(self._file_path("unicode_arguments.html")),
             [
                 u('x is: drôle de petite voix m’a réveillé'),
                 u('x is: drôle de petite voix m’a réveillé'),
@@ -1017,16 +1018,16 @@
                 source = source.encode('utf-8')
             else:
                 source = source
-            templateargs = {'text':source}
+            templateargs = {'text': source}
         else:
             if syntax:
                 filename = 'unicode_syntax_error.html'
             else:
                 filename = 'unicode_runtime_error.html'
-            source = open(self._file_path(filename), 'rb').read()
+            source = util.read_file(self._file_path(filename), 'rb')
             if not utf8:
                 source = source.decode('utf-8')
-            templateargs = {'filename':self._file_path(filename)}
+            templateargs = {'filename': self._file_path(filename)}
         try:
             template = Template(**templateargs)
             if not syntax:
diff --git a/test/test_util.py b/test/test_util.py
index 2683cd7..c8034a1 100644
--- a/test/test_util.py
+++ b/test/test_util.py
@@ -33,12 +33,12 @@
     def test_read_file(self):
         fn = os.path.join(os.path.dirname(__file__), 'test_util.py')
         data = util.read_file(fn, 'rb')
-        self.failUnless('test_util' in str(data)) # str() for py3k
+        assert 'test_util' in str(data)  # str() for py3k
 
     @skip_if(lambda: compat.pypy, "Pypy does this differently")
     def test_load_module(self):
         fn = os.path.join(os.path.dirname(__file__), 'test_util.py')
-        module = util.load_module('mako.template', fn)
+        module = compat.load_module('mako.template', fn)
         import mako.template
         self.assertEqual(module, mako.template)