|
5 | 5 | # the BSD License: http://www.opensource.org/licenses/bsd-license.php
|
6 | 6 |
|
7 | 7 | importos,sys
|
8 |
| -fromgit.test.libimport* |
| 8 | +fromgit.test.libimport ( |
| 9 | +TestBase, |
| 10 | +patch_object, |
| 11 | +raises, |
| 12 | +assert_equal, |
| 13 | +assert_true, |
| 14 | +assert_match, |
| 15 | +fixture_path |
| 16 | +) |
9 | 17 | fromgitimportGit,GitCommandError
|
10 | 18 |
|
11 |
| -classTestGit(TestCase): |
12 |
| - |
13 |
| -@classmethod |
14 |
| -defsetUpAll(cls): |
15 |
| -cls.git=Git(GIT_REPO) |
| 19 | +classTestGit(TestBase): |
| 20 | + |
| 21 | +@classmethod |
| 22 | +defsetUpAll(cls): |
| 23 | +super(TestGit,cls).setUpAll() |
| 24 | +cls.git=Git(cls.rorepo.working_dir) |
16 | 25 |
|
17 |
| -@patch_object(Git,'execute') |
18 |
| -deftest_call_process_calls_execute(self,git): |
19 |
| -git.return_value='' |
20 |
| -self.git.version() |
21 |
| -assert_true(git.called) |
22 |
| -assert_equal(git.call_args, ((['git','version'],), {})) |
| 26 | +@patch_object(Git,'execute') |
| 27 | +deftest_call_process_calls_execute(self,git): |
| 28 | +git.return_value='' |
| 29 | +self.git.version() |
| 30 | +assert_true(git.called) |
| 31 | +assert_equal(git.call_args, ((['git','version'],), {})) |
23 | 32 |
|
24 |
| -@raises(GitCommandError) |
25 |
| -deftest_it_raises_errors(self): |
26 |
| -self.git.this_does_not_exist() |
| 33 | +@raises(GitCommandError) |
| 34 | +deftest_it_raises_errors(self): |
| 35 | +self.git.this_does_not_exist() |
27 | 36 |
|
28 | 37 |
|
29 |
| -deftest_it_transforms_kwargs_into_git_command_arguments(self): |
30 |
| -assert_equal(["-s"],self.git.transform_kwargs(**{'s':True})) |
31 |
| -assert_equal(["-s5"],self.git.transform_kwargs(**{'s':5})) |
| 38 | +deftest_it_transforms_kwargs_into_git_command_arguments(self): |
| 39 | +assert_equal(["-s"],self.git.transform_kwargs(**{'s':True})) |
| 40 | +assert_equal(["-s5"],self.git.transform_kwargs(**{'s':5})) |
32 | 41 |
|
33 |
| -assert_equal(["--max-count"],self.git.transform_kwargs(**{'max_count':True})) |
34 |
| -assert_equal(["--max-count=5"],self.git.transform_kwargs(**{'max_count':5})) |
| 42 | +assert_equal(["--max-count"],self.git.transform_kwargs(**{'max_count':True})) |
| 43 | +assert_equal(["--max-count=5"],self.git.transform_kwargs(**{'max_count':5})) |
35 | 44 |
|
36 |
| -assert_equal(["-s","-t"],self.git.transform_kwargs(**{'s':True,'t':True})) |
| 45 | +assert_equal(["-s","-t"],self.git.transform_kwargs(**{'s':True,'t':True})) |
37 | 46 |
|
38 |
| -deftest_it_executes_git_to_shell_and_returns_result(self): |
39 |
| -assert_match('^git version [\d\.]{2}.*$',self.git.execute(["git","version"])) |
| 47 | +deftest_it_executes_git_to_shell_and_returns_result(self): |
| 48 | +assert_match('^git version [\d\.]{2}.*$',self.git.execute(["git","version"])) |
40 | 49 |
|
41 |
| -deftest_it_accepts_stdin(self): |
42 |
| -filename=fixture_path("cat_file_blob") |
43 |
| -fh=open(filename,'r') |
44 |
| -assert_equal("70c379b63ffa0795fdbfbc128e5a2818397b7ef8", |
45 |
| -self.git.hash_object(istream=fh,stdin=True)) |
46 |
| -fh.close() |
| 50 | +deftest_it_accepts_stdin(self): |
| 51 | +filename=fixture_path("cat_file_blob") |
| 52 | +fh=open(filename,'r') |
| 53 | +assert_equal("70c379b63ffa0795fdbfbc128e5a2818397b7ef8", |
| 54 | +self.git.hash_object(istream=fh,stdin=True)) |
| 55 | +fh.close() |
47 | 56 |
|
48 |
| -@patch_object(Git,'execute') |
49 |
| -deftest_it_ignores_false_kwargs(self,git): |
50 |
| -# this_should_not_be_ignored=False implies it *should* be ignored |
51 |
| -output=self.git.version(pass_this_kwarg=False) |
52 |
| -assert_true("pass_this_kwarg"notingit.call_args[1]) |
53 |
| - |
54 |
| -deftest_persistent_cat_file_command(self): |
55 |
| -# read header only |
56 |
| -importsubprocessassp |
57 |
| -hexsha="b2339455342180c7cc1e9bba3e9f181f7baa5167" |
58 |
| -g=self.git.cat_file(batch_check=True,istream=sp.PIPE,as_process=True) |
59 |
| -g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n") |
60 |
| -g.stdin.flush() |
61 |
| -obj_info=g.stdout.readline() |
62 |
| - |
63 |
| -# read header + data |
64 |
| -g=self.git.cat_file(batch=True,istream=sp.PIPE,as_process=True) |
65 |
| -g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n") |
66 |
| -g.stdin.flush() |
67 |
| -obj_info_two=g.stdout.readline() |
68 |
| -assertobj_info==obj_info_two |
69 |
| - |
70 |
| -# read data - have to read it in one large chunk |
71 |
| -size=int(obj_info.split()[2]) |
72 |
| -data=g.stdout.read(size) |
73 |
| -terminating_newline=g.stdout.read(1) |
74 |
| - |
75 |
| -# now we should be able to read a new object |
76 |
| -g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n") |
77 |
| -g.stdin.flush() |
78 |
| -assertg.stdout.readline()==obj_info |
79 |
| - |
80 |
| - |
81 |
| -# same can be achived using the respective command functions |
82 |
| -hexsha,typename,size=self.git.get_object_header(hexsha) |
83 |
| -hexsha,typename_two,size_two,data=self.git.get_object_data(hexsha) |
84 |
| -asserttypename==typename_twoandsize==size_two |
| 57 | +@patch_object(Git,'execute') |
| 58 | +deftest_it_ignores_false_kwargs(self,git): |
| 59 | +# this_should_not_be_ignored=False implies it *should* be ignored |
| 60 | +output=self.git.version(pass_this_kwarg=False) |
| 61 | +assert_true("pass_this_kwarg"notingit.call_args[1]) |
| 62 | + |
| 63 | +deftest_persistent_cat_file_command(self): |
| 64 | +# read header only |
| 65 | +importsubprocessassp |
| 66 | +hexsha="b2339455342180c7cc1e9bba3e9f181f7baa5167" |
| 67 | +g=self.git.cat_file(batch_check=True,istream=sp.PIPE,as_process=True) |
| 68 | +g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n") |
| 69 | +g.stdin.flush() |
| 70 | +obj_info=g.stdout.readline() |
| 71 | + |
| 72 | +# read header + data |
| 73 | +g=self.git.cat_file(batch=True,istream=sp.PIPE,as_process=True) |
| 74 | +g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n") |
| 75 | +g.stdin.flush() |
| 76 | +obj_info_two=g.stdout.readline() |
| 77 | +assertobj_info==obj_info_two |
| 78 | + |
| 79 | +# read data - have to read it in one large chunk |
| 80 | +size=int(obj_info.split()[2]) |
| 81 | +data=g.stdout.read(size) |
| 82 | +terminating_newline=g.stdout.read(1) |
| 83 | + |
| 84 | +# now we should be able to read a new object |
| 85 | +g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n") |
| 86 | +g.stdin.flush() |
| 87 | +assertg.stdout.readline()==obj_info |
| 88 | + |
| 89 | + |
| 90 | +# same can be achived using the respective command functions |
| 91 | +hexsha,typename,size=self.git.get_object_header(hexsha) |
| 92 | +hexsha,typename_two,size_two,data=self.git.get_object_data(hexsha) |
| 93 | +asserttypename==typename_twoandsize==size_two |
| 94 | + |
| 95 | +deftest_version(self): |
| 96 | +v=self.git.version_info |
| 97 | +assertisinstance(v,tuple) |
| 98 | +forninv: |
| 99 | +assertisinstance(n,int) |
| 100 | +#END verify number types |