GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — GitPython/test/test_base.py at main · gitpython-developers/GitPython Expand file tree/ Copy pathtest_base.pyMore file actions 143 lines (123 loc) · 5.7 KB / Copy pathtest_base.pyFile metadata and controls143 lines (123 loc) · 5.7 KB 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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 # Copyright (C) 2008, 2009 Michael Trier ([email protected]) and contributors # # This module is part of GitPython and is released under the # 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/ import gc import os.path as osp import sys from io import BytesIO from unittest import skipIf from unittest.mock import patch import pytest import git.objects.base as base from git import Repo from git.objects import Blob, Commit, TagObject, Tree from git.objects.util import get_object_type_by_name from git.util import hex_to_bin from gitdb import OInfo from test.lib import TestBase as _TestBase from test.lib import with_rw_and_rw_remote_repo, with_rw_repo from test.lib.fixtures import fixture_repo, writable_fixture class TestBase(_TestBase): def tearDown(self): gc.collect() type_tuples = ( ("blob", "HEAD:git/objects/blob.py", "blob.py"), ("tree", "HEAD:git", "directory"), ("commit", "dated", None), ("tag", "annotated", None), ) def test_base_object(self): # Test interface of base object classes. types = (Blob, Tree, Commit, TagObject) self.assertEqual(len(types), len(self.type_tuples)) s = set() num_objs = 0 num_index_objs = 0 for obj_type, (typename, revision, path) in zip(types, self.type_tuples): hexsha = self.rorepo.git.rev_parse(revision) binsha = hex_to_bin(hexsha) item = None if path is None: item = obj_type(self.rorepo, binsha) else: item = obj_type(self.rorepo, binsha, 0, path) # END handle index objects num_objs += 1 self.assertEqual(item.hexsha, hexsha) self.assertEqual(item.type, typename) assert item.size self.assertEqual(item, item) self.assertNotEqual(not item, item) self.assertEqual(str(item), item.hexsha) assert repr(item) s.add(item) if isinstance(item, base.IndexObject): num_index_objs += 1 if hasattr(item, "path"): # Never runs here. assert not item.path.startswith("/") # Must be relative. assert isinstance(item.mode, int) # END index object check # Read from stream. data_stream = item.data_stream data = data_stream.read() assert data with writable_fixture("empty.sh") as temporary: with (temporary.path() / "stream").open("w+b") as tmpfile: self.assertEqual(item, item.stream_data(tmpfile)) tmpfile.seek(0) self.assertEqual(tmpfile.read(), data) for stored_type in (typename, typename.encode("ascii")): with patch.object(self.rorepo.odb, "info", return_value=OInfo(binsha, stored_type, item.size)): self.assertEqual(obj_type(self.rorepo, binsha).size, item.size) for wrong_type in types: if wrong_type is obj_type: continue invalid = wrong_type(self.rorepo, binsha) with self.assertRaisesRegex(ValueError, f"{hexsha}.*{typename}.*{wrong_type.type}"): invalid.size self.assertEqual(invalid.data_stream.read(), data) ostream = BytesIO() invalid.stream_data(ostream) self.assertEqual(ostream.getvalue(), data) # END for each object type to create # Each has a unique sha. self.assertEqual(len(s), num_objs) self.assertEqual(len(s | s), num_objs) self.assertEqual(num_index_objs, 2) def test_get_object_type_by_name(self): for tname in base.Object.TYPES: assert base.Object in get_object_type_by_name(tname).mro() # END for each known type self.assertRaises(ValueError, get_object_type_by_name, b"doesntexist") def test_object_resolution(self): # Objects must be resolved to shas so they compare equal. self.assertEqual(self.rorepo.head.reference.object, self.rorepo.active_branch.object) @with_rw_repo("HEAD", bare=True) def test_with_bare_rw_repo(self, bare_rw_repo: Repo): assert bare_rw_repo.config_reader("repository").getboolean("core", "bare") assert osp.isfile(osp.join(bare_rw_repo.git_dir, "HEAD")) assert osp.isdir(bare_rw_repo.working_dir) assert bare_rw_repo.working_tree_dir is None @with_rw_repo("release") def test_with_rw_repo(self, rw_repo: Repo): assert not rw_repo.config_reader("repository").getboolean("core", "bare") assert osp.isdir(rw_repo.working_tree_dir) assert osp.isdir(osp.join(rw_repo.working_tree_dir, "lib")) assert osp.isdir(rw_repo.working_dir) @pytest.mark.net @skipIf(sys.platform == "win32", "FIXME: Freezes! sometimes...") @with_rw_and_rw_remote_repo("release") def test_with_rw_remote_and_rw_repo(self, rw_repo, rw_remote_repo): assert not rw_repo.config_reader("repository").getboolean("core", "bare") assert rw_remote_repo.config_reader("repository").getboolean("core", "bare") assert osp.isdir(osp.join(rw_repo.working_tree_dir, "lib")) def test_add_unicode(self): filename = "שלום.txt" with fixture_repo("index.sh", "file", filename, "something", write=True) as repo: file_path = osp.join(repo.working_dir, filename) if sys.platform == "win32": repo.index.add([file_path]) else: repo.git.add(repo.working_dir) repo.index.commit("message") |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |