Package portage :: Package tests :: Package dep :: Module test_isvalidatom
[hide private]

Source Code for Module portage.tests.dep.test_isvalidatom

  1  # Copyright 2006-2013 Gentoo Foundation 
  2  # Distributed under the terms of the GNU General Public License v2 
  3   
  4  from portage.tests import TestCase 
  5  from portage.dep import isvalidatom 
  6   
7 -class IsValidAtomTestCase(object):
8 - def __init__(self, atom, expected, allow_wildcard=False, allow_repo=False):
9 self.atom = atom 10 self.expected = expected 11 self.allow_wildcard = allow_wildcard 12 self.allow_repo = allow_repo
13
14 -class IsValidAtom(TestCase):
15
16 - def testIsValidAtom(self):
17 18 test_cases = ( 19 IsValidAtomTestCase("sys-apps/portage", True), 20 IsValidAtomTestCase("=sys-apps/portage-2.1", True), 21 IsValidAtomTestCase("=sys-apps/portage-2.1*", True), 22 IsValidAtomTestCase(">=sys-apps/portage-2.1", True), 23 IsValidAtomTestCase("<=sys-apps/portage-2.1", True), 24 IsValidAtomTestCase(">sys-apps/portage-2.1", True), 25 IsValidAtomTestCase("<sys-apps/portage-2.1", True), 26 IsValidAtomTestCase("~sys-apps/portage-2.1", True), 27 IsValidAtomTestCase("sys-apps/portage:foo", True), 28 IsValidAtomTestCase("sys-apps/portage-2.1:foo", False), 29 IsValidAtomTestCase("sys-apps/portage-2.1:", False), 30 IsValidAtomTestCase("sys-apps/portage-2.1:", False), 31 IsValidAtomTestCase("sys-apps/portage-2.1:[foo]", False), 32 IsValidAtomTestCase("sys-apps/portage", True), 33 IsValidAtomTestCase("sys-apps/portage", True), 34 IsValidAtomTestCase("sys-apps/portage", True), 35 IsValidAtomTestCase("sys-apps/portage", True), 36 IsValidAtomTestCase("sys-apps/portage", True), 37 IsValidAtomTestCase("sys-apps/portage", True), 38 IsValidAtomTestCase("sys-apps/portage", True), 39 40 IsValidAtomTestCase("=sys-apps/portage-2.2*:foo[bar?,!baz?,!doc=,build=]", True), 41 IsValidAtomTestCase("=sys-apps/portage-2.2*:foo[doc?]", True), 42 IsValidAtomTestCase("=sys-apps/portage-2.2*:foo[!doc?]", True), 43 IsValidAtomTestCase("=sys-apps/portage-2.2*:foo[doc=]", True), 44 IsValidAtomTestCase("=sys-apps/portage-2.2*:foo[!doc=]", True), 45 IsValidAtomTestCase("=sys-apps/portage-2.2*:foo[!doc]", False), 46 IsValidAtomTestCase("=sys-apps/portage-2.2*:foo[!-doc]", False), 47 IsValidAtomTestCase("=sys-apps/portage-2.2*:foo[!-doc=]", False), 48 IsValidAtomTestCase("=sys-apps/portage-2.2*:foo[!-doc?]", False), 49 IsValidAtomTestCase("=sys-apps/portage-2.2*:foo[-doc?]", False), 50 IsValidAtomTestCase("=sys-apps/portage-2.2*:foo[-doc=]", False), 51 IsValidAtomTestCase("=sys-apps/portage-2.2*:foo[-doc!=]", False), 52 IsValidAtomTestCase("=sys-apps/portage-2.2*:foo[-doc=]", False), 53 IsValidAtomTestCase("=sys-apps/portage-2.2*:foo[bar][-baz][doc?][!build?]", False), 54 IsValidAtomTestCase("=sys-apps/portage-2.2*:foo[bar,-baz,doc?,!build?]", True), 55 IsValidAtomTestCase("=sys-apps/portage-2.2*:foo[bar,-baz,doc?,!build?,]", False), 56 IsValidAtomTestCase("=sys-apps/portage-2.2*:foo[,bar,-baz,doc?,!build?]", False), 57 IsValidAtomTestCase("=sys-apps/portage-2.2*:foo[bar,-baz][doc?,!build?]", False), 58 IsValidAtomTestCase("=sys-apps/portage-2.2*:foo[bar][doc,build]", False), 59 IsValidAtomTestCase(">~cate-gory/foo-1.0", False), 60 IsValidAtomTestCase(">~category/foo-1.0", False), 61 IsValidAtomTestCase("<~category/foo-1.0", False), 62 IsValidAtomTestCase("###cat/foo-1.0", False), 63 IsValidAtomTestCase("~sys-apps/portage", False), 64 IsValidAtomTestCase("portage", False), 65 IsValidAtomTestCase("=portage", False), 66 IsValidAtomTestCase(">=portage-2.1", False), 67 IsValidAtomTestCase("~portage-2.1", False), 68 IsValidAtomTestCase("=portage-2.1*", False), 69 IsValidAtomTestCase("null/portage", True), 70 IsValidAtomTestCase("null/portage*:0", False), 71 IsValidAtomTestCase(">=null/portage-2.1", True), 72 IsValidAtomTestCase(">=null/portage", False), 73 IsValidAtomTestCase(">null/portage", False), 74 IsValidAtomTestCase("=null/portage*", False), 75 IsValidAtomTestCase("=null/portage", False), 76 IsValidAtomTestCase("~null/portage", False), 77 IsValidAtomTestCase("<=null/portage", False), 78 IsValidAtomTestCase("<null/portage", False), 79 IsValidAtomTestCase("~null/portage-2.1", True), 80 IsValidAtomTestCase("=null/portage-2.1*", True), 81 IsValidAtomTestCase("null/portage-2.1*", False), 82 IsValidAtomTestCase("app-doc/php-docs-20071125", False), 83 IsValidAtomTestCase("app-doc/php-docs-20071125-r2", False), 84 IsValidAtomTestCase("=foo/bar-1-r1-1-r1", False), 85 IsValidAtomTestCase("foo/-z-1", False), 86 87 # These are invalid because pkg name must not end in hyphen 88 # followed by numbers 89 IsValidAtomTestCase("=foo/bar-1-r1-1-r1", False), 90 IsValidAtomTestCase("=foo/bar-123-1", False), 91 IsValidAtomTestCase("=foo/bar-123-1*", False), 92 IsValidAtomTestCase("foo/bar-123", False), 93 IsValidAtomTestCase("=foo/bar-123-1-r1", False), 94 IsValidAtomTestCase("=foo/bar-123-1-r1*", False), 95 IsValidAtomTestCase("foo/bar-123-r1", False), 96 IsValidAtomTestCase("foo/bar-1", False), 97 98 IsValidAtomTestCase("=foo/bar--baz-1-r1", True), 99 IsValidAtomTestCase("=foo/bar-baz--1-r1", True), 100 IsValidAtomTestCase("=foo/bar-baz---1-r1", True), 101 IsValidAtomTestCase("=foo/bar-baz---1", True), 102 IsValidAtomTestCase("=foo/bar-baz-1--r1", False), 103 IsValidAtomTestCase("games-strategy/ufo2000", True), 104 IsValidAtomTestCase("~games-strategy/ufo2000-0.1", True), 105 IsValidAtomTestCase("=media-libs/x264-20060810", True), 106 IsValidAtomTestCase("foo/b", True), 107 IsValidAtomTestCase("app-text/7plus", True), 108 IsValidAtomTestCase("foo/666", True), 109 IsValidAtomTestCase("=dev-libs/poppler-qt3-0.11*", True), 110 111 #Testing atoms with repositories 112 IsValidAtomTestCase("sys-apps/portage::repo_123-name", True, allow_repo=True), 113 IsValidAtomTestCase("=sys-apps/portage-2.1::repo", True, allow_repo=True), 114 IsValidAtomTestCase("=sys-apps/portage-2.1*::repo", True, allow_repo=True), 115 IsValidAtomTestCase("sys-apps/portage:foo::repo", True, allow_repo=True), 116 IsValidAtomTestCase("sys-apps/portage-2.1:foo::repo", False, allow_repo=True), 117 IsValidAtomTestCase("sys-apps/portage-2.1:::repo", False, allow_repo=True), 118 IsValidAtomTestCase("sys-apps/portage-2.1:::repo[foo]", False, allow_repo=True), 119 IsValidAtomTestCase("=sys-apps/portage-2.2*:foo::repo[bar?,!baz?,!doc=,build=]", True, allow_repo=True), 120 IsValidAtomTestCase("=sys-apps/portage-2.2*:foo::repo[doc?]", True, allow_repo=True), 121 IsValidAtomTestCase("=sys-apps/portage-2.2*:foo::repo[!doc]", False, allow_repo=True), 122 IsValidAtomTestCase("###cat/foo-1.0::repo", False, allow_repo=True), 123 IsValidAtomTestCase("~sys-apps/portage::repo", False, allow_repo=True), 124 IsValidAtomTestCase("portage::repo", False, allow_repo=True), 125 IsValidAtomTestCase("=portage::repo", False, allow_repo=True), 126 IsValidAtomTestCase("null/portage::repo", True, allow_repo=True), 127 IsValidAtomTestCase("app-doc/php-docs-20071125::repo", False, allow_repo=True), 128 IsValidAtomTestCase("=foo/bar-1-r1-1-r1::repo", False, allow_repo=True), 129 130 IsValidAtomTestCase("sys-apps/portage::repo_123-name", False, allow_repo=False), 131 IsValidAtomTestCase("=sys-apps/portage-2.1::repo", False, allow_repo=False), 132 IsValidAtomTestCase("=sys-apps/portage-2.1*::repo", False, allow_repo=False), 133 IsValidAtomTestCase("sys-apps/portage:foo::repo", False, allow_repo=False), 134 IsValidAtomTestCase("=sys-apps/portage-2.2*:foo::repo[bar?,!baz?,!doc=,build=]", False, allow_repo=False), 135 IsValidAtomTestCase("=sys-apps/portage-2.2*:foo::repo[doc?]", False, allow_repo=False), 136 IsValidAtomTestCase("null/portage::repo", False, allow_repo=False), 137 138 IsValidAtomTestCase("virtual/ffmpeg:0/53", True), 139 IsValidAtomTestCase("virtual/ffmpeg:0/53=", True), 140 IsValidAtomTestCase("virtual/ffmpeg:0/53*", False), 141 IsValidAtomTestCase("virtual/ffmpeg:=", True), 142 IsValidAtomTestCase("virtual/ffmpeg:0=", True), 143 IsValidAtomTestCase("virtual/ffmpeg:*", True), 144 IsValidAtomTestCase("virtual/ffmpeg:0*", False), 145 IsValidAtomTestCase("virtual/ffmpeg:0", True), 146 147 # Wildcard atoms 148 IsValidAtomTestCase("*/portage-2.1", False, allow_wildcard=True), 149 ) 150 151 for test_case in test_cases: 152 if test_case.expected: 153 atom_type = "valid" 154 else: 155 atom_type = "invalid" 156 self.assertEqual(bool(isvalidatom(test_case.atom, allow_wildcard=test_case.allow_wildcard, 157 allow_repo=test_case.allow_repo)), test_case.expected, 158 msg="isvalidatom(%s) != %s" % (test_case.atom, test_case.expected))
159