1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
#!/usr/bin/atheist
# -*- mode:python; coding:utf-8 -*-
import sys
import os
import unittest2 as unittest
from fs.memoryfs import MemoryFS
from pyDoubles.framework import *
sys.path.append('$basedir')
import go2
def create_basic_dirs(fs):
home = go2.USERDIR
fs.makedir(home, recursive=True)
class Test_chdir_decorator(unittest.TestCase):
def setUp(self):
self.fs = MemoryFS()
create_basic_dirs(self.fs)
config = go2.get_config([])
config.fs = self.fs
go2.config = config
os.chdir(go2.USERDIR)
def tearDown(self):
pass
def mkdir(self, name):
path = os.path.join(go2.USERDIR, name)
self.fs.makedir(path, name)
return path
def test_no_pattern(self):
spy = empty_spy()
go2.save_target = spy.save_target
go2.chdir_decorator()
assert_that_was_called(spy.save_target).with_args(go2.USERDIR)
def test_no_hyphen(self):
go2.config.pattern = ['-']
spy = empty_spy()
go2.save_target = spy.save_target
go2.chdir_decorator()
assert_that_was_called(spy.save_target).with_args('-')
def mock_dir_history_save(self, relpath):
path = self.mkdir(relpath)
mock = empty_mock()
go2.save_in_history = mock.save_in_history
go2.save_target = mock.save_target
expect_call(mock.save_in_history).with_args(path)
expect_call(mock.save_target).with_args(path)
return mock
def test_existing_dir_1_word(self):
go2.config.pattern = ['foo']
mock = self.mock_dir_history_save('foo')
go2.chdir_decorator()
mock.assert_that_is_satisfied()
def test_existing_dir_2_words(self):
go2.config.pattern = ['foo bar']
mock = self.mock_dir_history_save('foo bar')
go2.chdir_decorator()
mock.assert_that_is_satisfied()
UnitTestCase()
|