FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
GitPython/test/git/test_diff.py at 0.2 · og-python-scripts/GitPython · GitHub
og-python-scripts
/
GitPython
Public
forked from
gitpython-developers/GitPython
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
GitPython
/
test
/
git
/
test_diff.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
103 lines (85 loc) · 4.31 KB
Breadcrumbs
GitPython
/
test
/
git
/
test_diff.py
Copy path
File metadata and controls
103 lines (85 loc) · 4.31 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# test_diff.py
# Copyright (C) 2008, 2009 Michael Trier (mtrier@gmail.com) and contributors
#
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
from
test
.
testlib
import
*
from
git
import
*
class
TestDiff
(
TestBase
):
def
_assert_diff_format
(
self
,
diffs
):
# verify that the format of the diff is sane
for
diff
in
diffs
:
if
diff
.
a_blob
:
assert
not
diff
.
a_blob
.
path
.
endswith
(
'
\n
'
)
if
diff
.
b_blob
:
assert
not
diff
.
b_blob
.
path
.
endswith
(
'
\n
'
)
# END for each diff
return
diffs
def
test_list_from_string_new_mode
(
self
):
output
=
ListProcessAdapter
(
fixture
(
'diff_new_mode'
))
diffs
=
Diff
.
_index_from_patch_format
(
self
.
rorepo
,
output
.
stdout
)
self
.
_assert_diff_format
(
diffs
)
assert_equal
(
1
,
len
(
diffs
))
assert_equal
(
10
,
len
(
diffs
[
0
].
diff
.
splitlines
()))
def
test_diff_with_rename
(
self
):
output
=
ListProcessAdapter
(
fixture
(
'diff_rename'
))
diffs
=
Diff
.
_index_from_patch_format
(
self
.
rorepo
,
output
.
stdout
)
self
.
_assert_diff_format
(
diffs
)
assert_equal
(
1
,
len
(
diffs
))
diff
=
diffs
[
0
]
assert_true
(
diff
.
renamed
)
assert_equal
(
diff
.
rename_from
,
'AUTHORS'
)
assert_equal
(
diff
.
rename_to
,
'CONTRIBUTORS'
)
def
test_diff_patch_format
(
self
):
# test all of the 'old' format diffs for completness - it should at least
# be able to deal with it
fixtures
=
(
"diff_2"
,
"diff_2f"
,
"diff_f"
,
"diff_i"
,
"diff_mode_only"
,
"diff_new_mode"
,
"diff_numstat"
,
"diff_p"
,
"diff_rename"
,
"diff_tree_numstat_root"
)
for
fixture_name
in
fixtures
:
diff_proc
=
ListProcessAdapter
(
fixture
(
fixture_name
))
diffs
=
Diff
.
_index_from_patch_format
(
self
.
rorepo
,
diff_proc
.
stdout
)
# END for each fixture
def
test_diff_interface
(
self
):
# test a few variations of the main diff routine
assertion_map
=
dict
()
for
i
,
commit
in
enumerate
(
self
.
rorepo
.
iter_commits
(
'0.1.6'
,
max_count
=
2
)):
diff_item
=
commit
if
i
%
2
==
0
:
diff_item
=
commit
.
tree
# END use tree every second item
for
other
in
(
None
,
commit
.
Index
,
commit
.
parents
[
0
]):
for
paths
in
(
None
,
"CHANGES"
, (
"CHANGES"
,
"lib"
)):
for
create_patch
in
range
(
2
):
diff_index
=
diff_item
.
diff
(
other
,
paths
,
create_patch
)
assert
isinstance
(
diff_index
,
DiffIndex
)
if
diff_index
:
self
.
_assert_diff_format
(
diff_index
)
for
ct
in
DiffIndex
.
change_type
:
key
=
'ct_%s'
%
ct
assertion_map
.
setdefault
(
key
,
0
)
assertion_map
[
key
]
=
assertion_map
[
key
]
+
len
(
list
(
diff_index
.
iter_change_type
(
ct
)))
# END for each changetype
# check entries
diff_set
=
set
()
diff_set
.
add
(
diff_index
[
0
])
diff_set
.
add
(
diff_index
[
0
])
assert
len
(
diff_set
)
==
1
assert
diff_index
[
0
]
==
diff_index
[
0
]
assert
not
(
diff_index
[
0
]
!=
diff_index
[
0
])
# END diff index checking
# END for each patch option
# END for each path option
# END for each other side
# END for each commit
# assert we could always find at least one instance of the members we
# can iterate in the diff index - if not this indicates its not working correctly
# or our test does not span the whole range of possibilities
for
key
,
value
in
assertion_map
.
items
():
assert
value
,
"Did not find diff for %s"
%
key
# END for each iteration type
# test path not existing in the index - should be ignored
c
=
self
.
rorepo
.
head
.
commit
cp
=
c
.
parents
[
0
]
diff_index
=
c
.
diff
(
cp
, [
"does/not/exist"
])
assert
len
(
diff_index
)
==
0
Back
|
FazBrowse Home
|
New Git URL