| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,10 +9,6 @@ Tom Preston-Werner and Chris Wanstrath. | |||
| 9 | 9 | ||
| 10 | 10 | .. _grit: http://grit.rubyforge.org | |
| 11 | 11 | ||
| 12 | - The idea for the ``method_missing`` stuff was `taken from this blog post`_. | ||
| 13 | - | ||
| 14 | - .. _taken from this blog post: http://blog.iffy.us/?p=43 | ||
| 15 | - | ||
| 16 | 12 | REQUIREMENTS | |
| 17 | 13 | ============ | |
| 18 | 14 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -184,7 +184,7 @@ What Else? | |||
| 184 | 184 | ||
| 185 | 185 | There is more stuff in there, like the ability to tar or gzip repos, stats, | |
| 186 | 186 | log, blame, and probably a few other things. Additionally calls to the git | |
| 187 | - instance are handled through a ``method_missing`` construct, which makes | ||
| 187 | + instance are handled through a ``__getattr__`` construct, which makes | ||
| 188 | 188 | available any git commands directly, with a nice conversion of Python dicts | |
| 189 | 189 | to command line parameters. | |
| 190 | 190 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,6 @@ | |||
| 8 | 8 | import subprocess | |
| 9 | 9 | import re | |
| 10 | 10 | from utils import * | |
| 11 | - from method_missing import MethodMissingMixin | ||
| 12 | 11 | from errors import GitCommandError | |
| 13 | 12 | ||
| 14 | 13 | # Enables debugging of GitPython's git commands | |
@@ -17,14 +16,19 @@ | |||
| 17 | 16 | execute_kwargs = ('istream', 'with_keep_cwd', 'with_extended_output', | |
| 18 | 17 | 'with_exceptions', 'with_raw_output') | |
| 19 | 18 | ||
| 20 | - class Git(MethodMissingMixin): | ||
| 19 | + class Git(object): | ||
| 21 | 20 | """ | |
| 22 | 21 | The Git class manages communication with the Git binary | |
| 23 | 22 | """ | |
| 24 | 23 | def __init__(self, git_dir): | |
| 25 | 24 | super(Git, self).__init__() | |
| 26 | 25 | self.git_dir = git_dir | |
| 27 | 26 | ||
| 27 | + def __getattr__(self, name): | ||
| 28 | + if name[:1] == '_': | ||
| 29 | + raise AttributeError(name) | ||
| 30 | + return lambda *args, **kwargs: self._call_process(name, *args, **kwargs) | ||
| 31 | + | ||
| 28 | 32 | @property | |
| 29 | 33 | def get_dir(self): | |
| 30 | 34 | return self.git_dir | |
@@ -131,7 +135,7 @@ def transform_kwargs(self, **kwargs): | |||
| 131 | 135 | args.append("--%s=%s" % (dashify(k), v)) | |
| 132 | 136 | return args | |
| 133 | 137 | ||
| 134 | - def method_missing(self, method, *args, **kwargs): | ||
| 138 | + def _call_process(self, method, *args, **kwargs): | ||
| 135 | 139 | """ | |
| 136 | 140 | Run the given git command with the specified arguments and return | |
| 137 | 141 | the result as a String | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,15 +12,15 @@ class TestBlob(object): | |||
| 12 | 12 | def setup(self): | |
| 13 | 13 | self.repo = Repo(GIT_REPO) | |
| 14 | 14 | ||
| 15 | - @patch(Git, 'method_missing') | ||
| 15 | + @patch(Git, '_call_process') | ||
| 16 | 16 | def test_should_return_blob_contents(self, git): | |
| 17 | 17 | git.return_value = fixture('cat_file_blob') | |
| 18 | 18 | blob = Blob(self.repo, **{'id': 'abc'}) | |
| 19 | 19 | assert_equal("Hello world", blob.data) | |
| 20 | 20 | assert_true(git.called) | |
| 21 | 21 | assert_equal(git.call_args, (('cat_file', 'abc'), {'p': True})) | |
| 22 | 22 | ||
| 23 | - @patch(Git, 'method_missing') | ||
| 23 | + @patch(Git, '_call_process') | ||
| 24 | 24 | def test_should_cache_data(self, git): | |
| 25 | 25 | git.return_value = fixture('cat_file_blob') | |
| 26 | 26 | blob = Blob(self.repo, **{'id': 'abc'}) | |
@@ -30,15 +30,15 @@ def test_should_cache_data(self, git): | |||
| 30 | 30 | assert_equal(git.call_count, 1) | |
| 31 | 31 | assert_equal(git.call_args, (('cat_file', 'abc'), {'p': True})) | |
| 32 | 32 | ||
| 33 | - @patch(Git, 'method_missing') | ||
| 33 | + @patch(Git, '_call_process') | ||
| 34 | 34 | def test_should_return_file_size(self, git): | |
| 35 | 35 | git.return_value = fixture('cat_file_blob_size') | |
| 36 | 36 | blob = Blob(self.repo, **{'id': 'abc'}) | |
| 37 | 37 | assert_equal(11, blob.size) | |
| 38 | 38 | assert_true(git.called) | |
| 39 | 39 | assert_equal(git.call_args, (('cat_file', 'abc'), {'s': True})) | |
| 40 | 40 | ||
| 41 | - @patch(Git, 'method_missing') | ||
| 41 | + @patch(Git, '_call_process') | ||
| 42 | 42 | def test_should_cache_file_size(self, git): | |
| 43 | 43 | git.return_value = fixture('cat_file_blob_size') | |
| 44 | 44 | blob = Blob(self.repo, **{'id': 'abc'}) | |
@@ -56,7 +56,7 @@ def test_mime_type_should_return_text_plain_for_unknown_types(self): | |||
| 56 | 56 | blob = Blob(self.repo, **{'id': 'abc'}) | |
| 57 | 57 | assert_equal("text/plain", blob.mime_type) | |
| 58 | 58 | ||
| 59 | - @patch(Git, 'method_missing') | ||
| 59 | + @patch(Git, '_call_process') | ||
| 60 | 60 | def test_should_display_blame_information(self, git): | |
| 61 | 61 | git.return_value = fixture('blame') | |
| 62 | 62 | b = Blob.blame(self.repo, 'master', 'lib/git.py') | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,7 +11,7 @@ class TestCommit(object): | |||
| 11 | 11 | def setup(self): | |
| 12 | 12 | self.repo = Repo(GIT_REPO) | |
| 13 | 13 | ||
| 14 | - @patch(Git, 'method_missing') | ||
| 14 | + @patch(Git, '_call_process') | ||
| 15 | 15 | def test_bake(self, git): | |
| 16 | 16 | git.return_value = fixture('rev_list_single') | |
| 17 | 17 | ||
@@ -24,12 +24,12 @@ def test_bake(self, git): | |||
| 24 | 24 | assert_true(git.called) | |
| 25 | 25 | assert_equal(git.call_args, (('rev_list', '4c8124ffcf4039d292442eeccabdeca5af5c5017'), {'pretty': 'raw', 'max_count': 1})) | |
| 26 | 26 | ||
| 27 | - @patch(Git, 'method_missing') | ||
| 27 | + @patch(Git, '_call_process') | ||
| 28 | 28 | def test_id_abbrev(self, git): | |
| 29 | 29 | git.return_value = fixture('rev_list_commit_idabbrev') | |
| 30 | 30 | assert_equal('80f136f', self.repo.commit('80f136f500dfdb8c3e8abf4ae716f875f0a1b57f').id_abbrev) | |
| 31 | 31 | ||
| 32 | - @patch(Git, 'method_missing') | ||
| 32 | + @patch(Git, '_call_process') | ||
| 33 | 33 | def test_diff(self, git): | |
| 34 | 34 | git.return_value = fixture('diff_p') | |
| 35 | 35 | ||
@@ -54,7 +54,7 @@ def test_diff(self, git): | |||
| 54 | 54 | assert_true(git.called) | |
| 55 | 55 | assert_equal(git.call_args, (('diff', 'master'), {'full_index': True})) | |
| 56 | 56 | ||
| 57 | - @patch(Git, 'method_missing') | ||
| 57 | + @patch(Git, '_call_process') | ||
| 58 | 58 | def test_diff_with_two_commits(self, git): | |
| 59 | 59 | git.return_value = fixture('diff_2') | |
| 60 | 60 | ||
@@ -65,7 +65,7 @@ def test_diff_with_two_commits(self, git): | |||
| 65 | 65 | assert_true(git.called) | |
| 66 | 66 | assert_equal(git.call_args, (('diff', '59ddc32', '13d27d5'), {'full_index': True})) | |
| 67 | 67 | ||
| 68 | - @patch(Git, 'method_missing') | ||
| 68 | + @patch(Git, '_call_process') | ||
| 69 | 69 | def test_diff_with_files(self, git): | |
| 70 | 70 | git.return_value = fixture('diff_f') | |
| 71 | 71 | ||
@@ -77,7 +77,7 @@ def test_diff_with_files(self, git): | |||
| 77 | 77 | assert_true(git.called) | |
| 78 | 78 | assert_equal(git.call_args, (('diff', '59ddc32', '--', 'lib'), {'full_index': True})) | |
| 79 | 79 | ||
| 80 | - @patch(Git, 'method_missing') | ||
| 80 | + @patch(Git, '_call_process') | ||
| 81 | 81 | def test_diff_with_two_commits_and_files(self, git): | |
| 82 | 82 | git.return_value = fixture('diff_2f') | |
| 83 | 83 | ||
@@ -89,7 +89,7 @@ def test_diff_with_two_commits_and_files(self, git): | |||
| 89 | 89 | assert_true(git.called) | |
| 90 | 90 | assert_equal(git.call_args, (('diff', '59ddc32', '13d27d5', '--', 'lib'), {'full_index': True})) | |
| 91 | 91 | ||
| 92 | - @patch(Git, 'method_missing') | ||
| 92 | + @patch(Git, '_call_process') | ||
| 93 | 93 | def test_diffs(self, git): | |
| 94 | 94 | git.return_value = fixture('diff_p') | |
| 95 | 95 | ||
@@ -117,7 +117,7 @@ def test_diffs(self, git): | |||
| 117 | 117 | '91169e1f5fa4de2eaea3f176461f5dc784796769', | |
| 118 | 118 | ), {'full_index': True})) | |
| 119 | 119 | ||
| 120 | - @patch(Git, 'method_missing') | ||
| 120 | + @patch(Git, '_call_process') | ||
| 121 | 121 | def test_diffs_on_initial_import(self, git): | |
| 122 | 122 | git.return_value = fixture('diff_i') | |
| 123 | 123 | ||
@@ -144,7 +144,7 @@ def test_diffs_on_initial_import(self, git): | |||
| 144 | 144 | assert_true(git.called) | |
| 145 | 145 | assert_equal(git.call_args, (('show', '634396b2f541a9f2d58b00be1a07f0c358b999b3'), {'full_index': True, 'pretty': 'raw'})) | |
| 146 | 146 | ||
| 147 | - @patch(Git, 'method_missing') | ||
| 147 | + @patch(Git, '_call_process') | ||
| 148 | 148 | def test_diffs_on_initial_import_with_empty_commit(self, git): | |
| 149 | 149 | git.return_value = fixture('show_empty_commit') | |
| 150 | 150 | ||
@@ -156,7 +156,7 @@ def test_diffs_on_initial_import_with_empty_commit(self, git): | |||
| 156 | 156 | assert_true(git.called) | |
| 157 | 157 | assert_equal(git.call_args, (('show', '634396b2f541a9f2d58b00be1a07f0c358b999b3'), {'full_index': True, 'pretty': 'raw'})) | |
| 158 | 158 | ||
| 159 | - @patch(Git, 'method_missing') | ||
| 159 | + @patch(Git, '_call_process') | ||
| 160 | 160 | def test_diffs_with_mode_only_change(self, git): | |
| 161 | 161 | git.return_value = fixture('diff_mode_only') | |
| 162 | 162 | ||
@@ -171,7 +171,7 @@ def test_diffs_with_mode_only_change(self, git): | |||
| 171 | 171 | assert_true(git.called) | |
| 172 | 172 | assert_equal(git.call_args, (('show', '91169e1f5fa4de2eaea3f176461f5dc784796769'), {'full_index': True, 'pretty': 'raw'})) | |
| 173 | 173 | ||
| 174 | - @patch(Git, 'method_missing') | ||
| 174 | + @patch(Git, '_call_process') | ||
| 175 | 175 | def test_stats(self, git): | |
| 176 | 176 | git.return_value = fixture('diff_numstat') | |
| 177 | 177 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,11 +14,11 @@ def setup(self): | |||
| 14 | 14 | self.git = Git(base) | |
| 15 | 15 | ||
| 16 | 16 | @patch(Git, 'execute') | |
| 17 | - def test_method_missing_calls_execute(self, git): | ||
| 17 | + def test__call_process_calls_execute(self, git): | ||
| 18 | 18 | git.return_value = '' | |
| 19 | 19 | self.git.version() | |
| 20 | 20 | assert_true(git.called) | |
| 21 | - # assert_equal(git.call_args, ((("%s version " % self.git_bin_base),), {})) | ||
| 21 | + assert_equal(git.call_args, ((['git', 'version'],), {})) | ||
| 22 | 22 | ||
| 23 | 23 | @raises(GitCommandError) | |
| 24 | 24 | def test_it_raises_errors(self): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,7 +11,7 @@ class TestHead(object): | |||
| 11 | 11 | def setup(self): | |
| 12 | 12 | self.repo = Repo(GIT_REPO) | |
| 13 | 13 | ||
| 14 | - @patch(Git, 'method_missing') | ||
| 14 | + @patch(Git, '_call_process') | ||
| 15 | 15 | def test_repr(self, git): | |
| 16 | 16 | git.return_value = fixture('for_each_ref') | |
| 17 | 17 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,7 +28,7 @@ def test_heads_should_return_array_of_head_objects(self): | |||
| 28 | 28 | for head in self.repo.heads: | |
| 29 | 29 | assert_equal(Head, head.__class__) | |
| 30 | 30 | ||
| 31 | - @patch(Git, 'method_missing') | ||
| 31 | + @patch(Git, '_call_process') | ||
| 32 | 32 | def test_heads_should_populate_head_data(self, git): | |
| 33 | 33 | git.return_value = fixture('for_each_ref') | |
| 34 | 34 | ||
@@ -39,7 +39,7 @@ def test_heads_should_populate_head_data(self, git): | |||
| 39 | 39 | assert_true(git.called) | |
| 40 | 40 | assert_equal(git.call_args, (('for_each_ref', 'refs/heads'), {'sort': 'committerdate', 'format': '%(refname)%00%(objectname)'})) | |
| 41 | 41 | ||
| 42 | - @patch(Git, 'method_missing') | ||
| 42 | + @patch(Git, '_call_process') | ||
| 43 | 43 | def test_commits(self, git): | |
| 44 | 44 | git.return_value = fixture('rev_list') | |
| 45 | 45 | ||
@@ -67,7 +67,7 @@ def test_commits(self, git): | |||
| 67 | 67 | assert_true(git.called) | |
| 68 | 68 | assert_equal(git.call_args, (('rev_list', 'master'), {'skip': 0, 'pretty': 'raw', 'max_count': 10})) | |
| 69 | 69 | ||
| 70 | - @patch(Git, 'method_missing') | ||
| 70 | + @patch(Git, '_call_process') | ||
| 71 | 71 | def test_commit_count(self, git): | |
| 72 | 72 | git.return_value = fixture('rev_list_count') | |
| 73 | 73 | ||
@@ -76,7 +76,7 @@ def test_commit_count(self, git): | |||
| 76 | 76 | assert_true(git.called) | |
| 77 | 77 | assert_equal(git.call_args, (('rev_list', 'master'), {})) | |
| 78 | 78 | ||
| 79 | - @patch(Git, 'method_missing') | ||
| 79 | + @patch(Git, '_call_process') | ||
| 80 | 80 | def test_commit(self, git): | |
| 81 | 81 | git.return_value = fixture('rev_list_single') | |
| 82 | 82 | ||
@@ -87,7 +87,7 @@ def test_commit(self, git): | |||
| 87 | 87 | assert_true(git.called) | |
| 88 | 88 | assert_equal(git.call_args, (('rev_list', '4c8124ffcf4039d292442eeccabdeca5af5c5017'), {'pretty': 'raw', 'max_count': 1})) | |
| 89 | 89 | ||
| 90 | - @patch(Git, 'method_missing') | ||
| 90 | + @patch(Git, '_call_process') | ||
| 91 | 91 | def test_tree(self, git): | |
| 92 | 92 | git.return_value = fixture('ls_tree_a') | |
| 93 | 93 | ||
@@ -99,7 +99,7 @@ def test_tree(self, git): | |||
| 99 | 99 | assert_true(git.called) | |
| 100 | 100 | assert_equal(git.call_args, (('ls_tree', 'master'), {})) | |
| 101 | 101 | ||
| 102 | - @patch(Git, 'method_missing') | ||
| 102 | + @patch(Git, '_call_process') | ||
| 103 | 103 | def test_blob(self, git): | |
| 104 | 104 | git.return_value = fixture('cat_file_blob') | |
| 105 | 105 | ||
@@ -110,7 +110,7 @@ def test_blob(self, git): | |||
| 110 | 110 | assert_equal(git.call_args, (('cat_file', 'abc'), {'p': True})) | |
| 111 | 111 | ||
| 112 | 112 | @patch(Repo, '__init__') | |
| 113 | - @patch(Git, 'method_missing') | ||
| 113 | + @patch(Git, '_call_process') | ||
| 114 | 114 | def test_init_bare(self, repo, git): | |
| 115 | 115 | git.return_value = True | |
| 116 | 116 | ||
@@ -122,7 +122,7 @@ def test_init_bare(self, repo, git): | |||
| 122 | 122 | assert_equal(repo.call_args, (('repos/foo/bar.git',), {})) | |
| 123 | 123 | ||
| 124 | 124 | @patch(Repo, '__init__') | |
| 125 | - @patch(Git, 'method_missing') | ||
| 125 | + @patch(Git, '_call_process') | ||
| 126 | 126 | def test_init_bare_with_options(self, repo, git): | |
| 127 | 127 | git.return_value = True | |
| 128 | 128 | ||
@@ -134,7 +134,7 @@ def test_init_bare_with_options(self, repo, git): | |||
| 134 | 134 | assert_equal(repo.call_args, (('repos/foo/bar.git',), {})) | |
| 135 | 135 | ||
| 136 | 136 | @patch(Repo, '__init__') | |
| 137 | - @patch(Git, 'method_missing') | ||
| 137 | + @patch(Git, '_call_process') | ||
| 138 | 138 | def test_fork_bare(self, repo, git): | |
| 139 | 139 | git.return_value = None | |
| 140 | 140 | ||
@@ -145,7 +145,7 @@ def test_fork_bare(self, repo, git): | |||
| 145 | 145 | assert_true(repo.called) | |
| 146 | 146 | ||
| 147 | 147 | @patch(Repo, '__init__') | |
| 148 | - @patch(Git, 'method_missing') | ||
| 148 | + @patch(Git, '_call_process') | ||
| 149 | 149 | def test_fork_bare_with_options(self, repo, git): | |
| 150 | 150 | git.return_value = None | |
| 151 | 151 | ||
@@ -156,7 +156,7 @@ def test_fork_bare_with_options(self, repo, git): | |||
| 156 | 156 | {'bare': True, 'template': '/awesome'})) | |
| 157 | 157 | assert_true(repo.called) | |
| 158 | 158 | ||
| 159 | - @patch(Git, 'method_missing') | ||
| 159 | + @patch(Git, '_call_process') | ||
| 160 | 160 | def test_diff(self, git): | |
| 161 | 161 | self.repo.diff('master^', 'master') | |
| 162 | 162 | ||
@@ -173,7 +173,7 @@ def test_diff(self, git): | |||
| 173 | 173 | assert_true(git.called) | |
| 174 | 174 | assert_equal(git.call_args, (('diff', 'master^', 'master', '--', 'foo/bar', 'foo/baz'), {})) | |
| 175 | 175 | ||
| 176 | - @patch(Git, 'method_missing') | ||
| 176 | + @patch(Git, '_call_process') | ||
| 177 | 177 | def test_diff(self, git): | |
| 178 | 178 | git.return_value = fixture('diff_p') | |
| 179 | 179 | ||
@@ -248,7 +248,7 @@ def test_alternates_setter_empty(self, os): | |||
| 248 | 248 | def test_repr(self): | |
| 249 | 249 | assert_equal('<GitPython.Repo "%s/.git">' % os.path.abspath(GIT_REPO), repr(self.repo)) | |
| 250 | 250 | ||
| 251 | - @patch(Git, 'method_missing') | ||
| 251 | + @patch(Git, '_call_process') | ||
| 252 | 252 | def test_log(self, git): | |
| 253 | 253 | git.return_value = fixture('rev_list') | |
| 254 | 254 | assert_equal('4c8124ffcf4039d292442eeccabdeca5af5c5017', self.repo.log()[0].id) | |
@@ -257,15 +257,15 @@ def test_log(self, git): | |||
| 257 | 257 | assert_equal(git.call_count, 2) | |
| 258 | 258 | assert_equal(git.call_args, (('log', 'master'), {'pretty': 'raw'})) | |
| 259 | 259 | ||
| 260 | - @patch(Git, 'method_missing') | ||
| 260 | + @patch(Git, '_call_process') | ||
| 261 | 261 | def test_log_with_path_and_options(self, git): | |
| 262 | 262 | git.return_value = fixture('rev_list') | |
| 263 | 263 | self.repo.log('master', 'file.rb', **{'max_count': 1}) | |
| 264 | 264 | assert_true(git.called) | |
| 265 | 265 | assert_equal(git.call_args, (('log', 'master', '--', 'file.rb'), {'pretty': 'raw', 'max_count': 1})) | |
| 266 | 266 | ||
| 267 | - # @patch(Git, 'method_missing') | ||
| 268 | - # @patch(Git, 'method_missing') | ||
| 267 | + # @patch(Git, '_call_process') | ||
| 268 | + # @patch(Git, '_call_process') | ||
| 269 | 269 | # def test_commit_deltas_from_nothing_new(self, gitb, gita): | |
| 270 | 270 | # gitb.return_value = fixture("rev_list_delta_b") | |
| 271 | 271 | # gita.return_value = fixture("rev_list_delta_a") | |
| Back | FazBrowse Home | New Git URL |
0 commit comments