MCPcopy Create free account
hub / github.com/libgit2/pygit2 / test_read_tree

Function test_read_tree

test/test_tree.py:47–84  ·  view source on GitHub ↗
(barerepo: Repository)

Source from the content-addressed store, hash-verified

45
46
47def test_read_tree(barerepo: Repository) -> None:
48 tree = barerepo[TREE_SHA]
49 assert isinstance(tree, Tree)
50 with pytest.raises(TypeError):
51 tree[()] # type: ignore
52 with pytest.raises(TypeError):
53 tree / 123 # type: ignore
54 utils.assertRaisesWithArg(KeyError, 'abcd', lambda: tree['abcd'])
55 utils.assertRaisesWithArg(IndexError, -4, lambda: tree[-4])
56 utils.assertRaisesWithArg(IndexError, 3, lambda: tree[3])
57 utils.assertRaisesWithArg(KeyError, 'abcd', lambda: tree / 'abcd')
58
59 assert 3 == len(tree)
60 sha = '7f129fd57e31e935c6d60a0c794efe4e6927664b'
61 assert 'a' in tree
62 assertTreeEntryEqual(tree[0], sha, 'a', 0o0100644)
63 assertTreeEntryEqual(tree[-3], sha, 'a', 0o0100644)
64 assertTreeEntryEqual(tree['a'], sha, 'a', 0o0100644)
65 assertTreeEntryEqual(tree / 'a', sha, 'a', 0o0100644)
66
67 sha = '85f120ee4dac60d0719fd51731e4199aa5a37df6'
68 assert 'b' in tree
69 assertTreeEntryEqual(tree[1], sha, 'b', 0o0100644)
70 assertTreeEntryEqual(tree[-2], sha, 'b', 0o0100644)
71 assertTreeEntryEqual(tree['b'], sha, 'b', 0o0100644)
72 assertTreeEntryEqual(tree / 'b', sha, 'b', 0o0100644)
73
74 sha = '297efb891a47de80be0cfe9c639e4b8c9b450989'
75 assertTreeEntryEqual(tree['c/d'], sha, 'd', 0o0100644)
76 assertTreeEntryEqual(tree / 'c/d', sha, 'd', 0o0100644)
77 assertTreeEntryEqual(tree / 'c' / 'd', sha, 'd', 0o0100644) # type: ignore[operator]
78 assertTreeEntryEqual(tree['c']['d'], sha, 'd', 0o0100644) # type: ignore[index]
79 assertTreeEntryEqual((tree / 'c')['d'], sha, 'd', 0o0100644) # type: ignore[index]
80 utils.assertRaisesWithArg(KeyError, 'ab/cd', lambda: tree['ab/cd'])
81 utils.assertRaisesWithArg(KeyError, 'ab/cd', lambda: tree / 'ab/cd')
82 utils.assertRaisesWithArg(KeyError, 'ab', lambda: tree / 'c' / 'ab') # type: ignore[operator]
83 with pytest.raises(TypeError):
84 tree / 'a' / 'cd' # type: ignore
85
86
87def test_equality(barerepo: Repository) -> None:

Callers

nothing calls this directly

Calls 1

assertTreeEntryEqualFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…