1616Tests for `caso.manager` module.
1717"""
1818
19- import contextlib
2019import datetime
2120
2221from dateutil import tz
@@ -36,7 +35,7 @@ def setUp(self):
3635 "messenger" : mock .patch ('caso.messenger.Manager' ),
3736 }
3837 self .mocks = {}
39- for k , p in self . patchers . iteritems ():
38+ for k , p in six . iteritems (self . patchers ):
4039 self .mocks [k ] = p .start ()
4140
4241 self .manager = manager .Manager ()
@@ -54,17 +53,20 @@ def test_lastrun_does_not_exist(self):
5453
5554 def test_lastrun_exists (self ):
5655 expected = datetime .datetime (2014 , 12 , 10 , 13 , 10 , 26 , 664598 )
57- aux = six .StringIO (expected )
56+ aux = six .StringIO (str ( expected ) )
5857
59- with contextlib .nested (
60- mock .patch ("os.path.exists" ),
61- mock .patch ('__builtin__.open' )
62- ) as (path , fopen ):
63- fopen .return_value .__enter__ = lambda x : aux
64- fopen .return_value .__exit__ = mock .Mock ()
65- path .return_value = True
58+ if six .PY3 :
59+ builtins_open = 'builtins.open'
60+ else :
61+ builtins_open = '__builtin__.open'
6662
67- self .assertEqual (expected , self .manager .lastrun )
63+ with mock .patch ("os.path.exists" ) as path :
64+ with mock .patch (builtins_open ) as fopen :
65+ fopen .return_value .__enter__ = lambda x : aux
66+ fopen .return_value .__exit__ = mock .Mock ()
67+ path .return_value = True
68+
69+ self .assertEqual (expected , self .manager .lastrun )
6870
6971 def test_lastrun_is_invalid (self ):
7072 aux = six .StringIO ("foo" )
@@ -74,15 +76,18 @@ def test_lastrun_is_invalid(self):
7476 def call (self ):
7577 return self .manager .lastrun
7678
77- with contextlib .nested (
78- mock .patch ("os.path.exists" ),
79- mock .patch ('__builtin__.open' )
80- ) as (path , fopen ):
81- fopen .return_value .__enter__ = lambda x : aux
82- fopen .return_value .__exit__ = mock .Mock ()
83- path .return_value = True
79+ if six .PY3 :
80+ builtins_open = 'builtins.open'
81+ else :
82+ builtins_open = '__builtin__.open'
83+
84+ with mock .patch ("os.path.exists" ) as path :
85+ with mock .patch (builtins_open ) as fopen :
86+ fopen .return_value .__enter__ = lambda x : aux
87+ fopen .return_value .__exit__ = mock .Mock ()
88+ path .return_value = True
8489
85- self .assertRaises (ValueError , call , self )
90+ self .assertRaises (ValueError , call , self )
8691
8792 def test_dry_run (self ):
8893 self .flags (dry_run = True )
0 commit comments