Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1 | # Copyright (C) 2017-2018 Wind River Systems, Inc. |
| 2 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 3 | # SPDX-License-Identifier: GPL-2.0-only |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 4 | # |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 5 | |
| 6 | import unittest |
| 7 | import tempfile |
| 8 | import os |
| 9 | import bb |
| 10 | |
| 11 | from layerindexlib.tests.common import LayersTest |
| 12 | |
| 13 | import logging |
| 14 | |
| 15 | class LayerIndexObjectsTest(LayersTest): |
| 16 | def setUp(self): |
| 17 | from layerindexlib import LayerIndexObj, Branch, LayerItem, LayerBranch, LayerDependency, Recipe, Machine, Distro |
| 18 | |
| 19 | LayersTest.setUp(self) |
| 20 | |
| 21 | self.index = LayerIndexObj() |
| 22 | |
| 23 | branchId = 0 |
| 24 | layerItemId = 0 |
| 25 | layerBranchId = 0 |
| 26 | layerDependencyId = 0 |
| 27 | recipeId = 0 |
| 28 | machineId = 0 |
| 29 | distroId = 0 |
| 30 | |
| 31 | self.index.branches = {} |
| 32 | self.index.layerItems = {} |
| 33 | self.index.layerBranches = {} |
| 34 | self.index.layerDependencies = {} |
| 35 | self.index.recipes = {} |
| 36 | self.index.machines = {} |
| 37 | self.index.distros = {} |
| 38 | |
| 39 | branchId += 1 |
| 40 | self.index.branches[branchId] = Branch(self.index) |
| 41 | self.index.branches[branchId].define_data(branchId, |
| 42 | 'test_branch', 'bb_test_branch') |
| 43 | self.index.branches[branchId].lockData() |
| 44 | |
| 45 | layerItemId +=1 |
| 46 | self.index.layerItems[layerItemId] = LayerItem(self.index) |
| 47 | self.index.layerItems[layerItemId].define_data(layerItemId, |
| 48 | 'test_layerItem', vcs_url='git://git_test_url/test_layerItem') |
| 49 | self.index.layerItems[layerItemId].lockData() |
| 50 | |
| 51 | layerBranchId +=1 |
| 52 | self.index.layerBranches[layerBranchId] = LayerBranch(self.index) |
| 53 | self.index.layerBranches[layerBranchId].define_data(layerBranchId, |
| 54 | 'test_collection', '99', layerItemId, |
| 55 | branchId) |
| 56 | |
| 57 | recipeId += 1 |
| 58 | self.index.recipes[recipeId] = Recipe(self.index) |
| 59 | self.index.recipes[recipeId].define_data(recipeId, 'test_git.bb', |
| 60 | 'recipes-test', 'test', 'git', |
| 61 | layerBranchId) |
| 62 | |
| 63 | machineId += 1 |
| 64 | self.index.machines[machineId] = Machine(self.index) |
| 65 | self.index.machines[machineId].define_data(machineId, |
| 66 | 'test_machine', 'test_machine', |
| 67 | layerBranchId) |
| 68 | |
| 69 | distroId += 1 |
| 70 | self.index.distros[distroId] = Distro(self.index) |
| 71 | self.index.distros[distroId].define_data(distroId, |
| 72 | 'test_distro', 'test_distro', |
| 73 | layerBranchId) |
| 74 | |
| 75 | layerItemId +=1 |
| 76 | self.index.layerItems[layerItemId] = LayerItem(self.index) |
| 77 | self.index.layerItems[layerItemId].define_data(layerItemId, 'test_layerItem 2', |
| 78 | vcs_url='git://git_test_url/test_layerItem') |
| 79 | |
| 80 | layerBranchId +=1 |
| 81 | self.index.layerBranches[layerBranchId] = LayerBranch(self.index) |
| 82 | self.index.layerBranches[layerBranchId].define_data(layerBranchId, |
| 83 | 'test_collection_2', '72', layerItemId, |
| 84 | branchId, actual_branch='some_other_branch') |
| 85 | |
| 86 | layerDependencyId += 1 |
| 87 | self.index.layerDependencies[layerDependencyId] = LayerDependency(self.index) |
| 88 | self.index.layerDependencies[layerDependencyId].define_data(layerDependencyId, |
| 89 | layerBranchId, 1) |
| 90 | |
| 91 | layerDependencyId += 1 |
| 92 | self.index.layerDependencies[layerDependencyId] = LayerDependency(self.index) |
| 93 | self.index.layerDependencies[layerDependencyId].define_data(layerDependencyId, |
| 94 | layerBranchId, 1, required=False) |
| 95 | |
| 96 | def test_branch(self): |
| 97 | branch = self.index.branches[1] |
| 98 | self.assertEqual(branch.id, 1) |
| 99 | self.assertEqual(branch.name, 'test_branch') |
| 100 | self.assertEqual(branch.short_description, 'test_branch') |
| 101 | self.assertEqual(branch.bitbake_branch, 'bb_test_branch') |
| 102 | |
| 103 | def test_layerItem(self): |
| 104 | layerItem = self.index.layerItems[1] |
| 105 | self.assertEqual(layerItem.id, 1) |
| 106 | self.assertEqual(layerItem.name, 'test_layerItem') |
| 107 | self.assertEqual(layerItem.summary, 'test_layerItem') |
| 108 | self.assertEqual(layerItem.description, 'test_layerItem') |
| 109 | self.assertEqual(layerItem.vcs_url, 'git://git_test_url/test_layerItem') |
| 110 | self.assertEqual(layerItem.vcs_web_url, None) |
| 111 | self.assertIsNone(layerItem.vcs_web_tree_base_url) |
| 112 | self.assertIsNone(layerItem.vcs_web_file_base_url) |
| 113 | self.assertIsNotNone(layerItem.updated) |
| 114 | |
| 115 | layerItem = self.index.layerItems[2] |
| 116 | self.assertEqual(layerItem.id, 2) |
| 117 | self.assertEqual(layerItem.name, 'test_layerItem 2') |
| 118 | self.assertEqual(layerItem.summary, 'test_layerItem 2') |
| 119 | self.assertEqual(layerItem.description, 'test_layerItem 2') |
| 120 | self.assertEqual(layerItem.vcs_url, 'git://git_test_url/test_layerItem') |
| 121 | self.assertIsNone(layerItem.vcs_web_url) |
| 122 | self.assertIsNone(layerItem.vcs_web_tree_base_url) |
| 123 | self.assertIsNone(layerItem.vcs_web_file_base_url) |
| 124 | self.assertIsNotNone(layerItem.updated) |
| 125 | |
| 126 | def test_layerBranch(self): |
| 127 | layerBranch = self.index.layerBranches[1] |
| 128 | self.assertEqual(layerBranch.id, 1) |
| 129 | self.assertEqual(layerBranch.collection, 'test_collection') |
| 130 | self.assertEqual(layerBranch.version, '99') |
| 131 | self.assertEqual(layerBranch.vcs_subdir, '') |
| 132 | self.assertEqual(layerBranch.actual_branch, 'test_branch') |
| 133 | self.assertIsNotNone(layerBranch.updated) |
| 134 | self.assertEqual(layerBranch.layer_id, 1) |
| 135 | self.assertEqual(layerBranch.branch_id, 1) |
| 136 | self.assertEqual(layerBranch.layer, self.index.layerItems[1]) |
| 137 | self.assertEqual(layerBranch.branch, self.index.branches[1]) |
| 138 | |
| 139 | layerBranch = self.index.layerBranches[2] |
| 140 | self.assertEqual(layerBranch.id, 2) |
| 141 | self.assertEqual(layerBranch.collection, 'test_collection_2') |
| 142 | self.assertEqual(layerBranch.version, '72') |
| 143 | self.assertEqual(layerBranch.vcs_subdir, '') |
| 144 | self.assertEqual(layerBranch.actual_branch, 'some_other_branch') |
| 145 | self.assertIsNotNone(layerBranch.updated) |
| 146 | self.assertEqual(layerBranch.layer_id, 2) |
| 147 | self.assertEqual(layerBranch.branch_id, 1) |
| 148 | self.assertEqual(layerBranch.layer, self.index.layerItems[2]) |
| 149 | self.assertEqual(layerBranch.branch, self.index.branches[1]) |
| 150 | |
| 151 | def test_layerDependency(self): |
| 152 | layerDependency = self.index.layerDependencies[1] |
| 153 | self.assertEqual(layerDependency.id, 1) |
| 154 | self.assertEqual(layerDependency.layerbranch_id, 2) |
| 155 | self.assertEqual(layerDependency.layerbranch, self.index.layerBranches[2]) |
| 156 | self.assertEqual(layerDependency.layer_id, 2) |
| 157 | self.assertEqual(layerDependency.layer, self.index.layerItems[2]) |
| 158 | self.assertTrue(layerDependency.required) |
| 159 | self.assertEqual(layerDependency.dependency_id, 1) |
| 160 | self.assertEqual(layerDependency.dependency, self.index.layerItems[1]) |
| 161 | self.assertEqual(layerDependency.dependency_layerBranch, self.index.layerBranches[1]) |
| 162 | |
| 163 | layerDependency = self.index.layerDependencies[2] |
| 164 | self.assertEqual(layerDependency.id, 2) |
| 165 | self.assertEqual(layerDependency.layerbranch_id, 2) |
| 166 | self.assertEqual(layerDependency.layerbranch, self.index.layerBranches[2]) |
| 167 | self.assertEqual(layerDependency.layer_id, 2) |
| 168 | self.assertEqual(layerDependency.layer, self.index.layerItems[2]) |
| 169 | self.assertFalse(layerDependency.required) |
| 170 | self.assertEqual(layerDependency.dependency_id, 1) |
| 171 | self.assertEqual(layerDependency.dependency, self.index.layerItems[1]) |
| 172 | self.assertEqual(layerDependency.dependency_layerBranch, self.index.layerBranches[1]) |
| 173 | |
| 174 | def test_recipe(self): |
| 175 | recipe = self.index.recipes[1] |
| 176 | self.assertEqual(recipe.id, 1) |
| 177 | self.assertEqual(recipe.layerbranch_id, 1) |
| 178 | self.assertEqual(recipe.layerbranch, self.index.layerBranches[1]) |
| 179 | self.assertEqual(recipe.layer_id, 1) |
| 180 | self.assertEqual(recipe.layer, self.index.layerItems[1]) |
| 181 | self.assertEqual(recipe.filename, 'test_git.bb') |
| 182 | self.assertEqual(recipe.filepath, 'recipes-test') |
| 183 | self.assertEqual(recipe.fullpath, 'recipes-test/test_git.bb') |
| 184 | self.assertEqual(recipe.summary, "") |
| 185 | self.assertEqual(recipe.description, "") |
| 186 | self.assertEqual(recipe.section, "") |
| 187 | self.assertEqual(recipe.pn, 'test') |
| 188 | self.assertEqual(recipe.pv, 'git') |
| 189 | self.assertEqual(recipe.license, "") |
| 190 | self.assertEqual(recipe.homepage, "") |
| 191 | self.assertEqual(recipe.bugtracker, "") |
| 192 | self.assertEqual(recipe.provides, "") |
| 193 | self.assertIsNotNone(recipe.updated) |
| 194 | self.assertEqual(recipe.inherits, "") |
| 195 | |
| 196 | def test_machine(self): |
| 197 | machine = self.index.machines[1] |
| 198 | self.assertEqual(machine.id, 1) |
| 199 | self.assertEqual(machine.layerbranch_id, 1) |
| 200 | self.assertEqual(machine.layerbranch, self.index.layerBranches[1]) |
| 201 | self.assertEqual(machine.layer_id, 1) |
| 202 | self.assertEqual(machine.layer, self.index.layerItems[1]) |
| 203 | self.assertEqual(machine.name, 'test_machine') |
| 204 | self.assertEqual(machine.description, 'test_machine') |
| 205 | self.assertIsNotNone(machine.updated) |
| 206 | |
| 207 | def test_distro(self): |
| 208 | distro = self.index.distros[1] |
| 209 | self.assertEqual(distro.id, 1) |
| 210 | self.assertEqual(distro.layerbranch_id, 1) |
| 211 | self.assertEqual(distro.layerbranch, self.index.layerBranches[1]) |
| 212 | self.assertEqual(distro.layer_id, 1) |
| 213 | self.assertEqual(distro.layer, self.index.layerItems[1]) |
| 214 | self.assertEqual(distro.name, 'test_distro') |
| 215 | self.assertEqual(distro.description, 'test_distro') |
| 216 | self.assertIsNotNone(distro.updated) |