def test_not_arch(self): actual = compile_debish('apache [!i386 !amd64]', deb, None) expected = ac([rc(eq, 'pdk', 'name', 'apache'), notc(oc([rc(eq, 'deb', 'arch', 'i386'), rc(eq, 'deb', 'arch', 'amd64')]))]) wrapper = ac([expected, rc(eq, 'pdk', 'type', 'deb')]) self.assert_equals(wrapper, actual)
def test_not_arch(self): actual = compile_debish('apache [!i386 !amd64]', deb, None) expected = ac([ rc(eq, 'pdk', 'name', 'apache'), notc( oc([ rc(eq, 'deb', 'arch', 'i386'), rc(eq, 'deb', 'arch', 'amd64') ])) ]) wrapper = ac([expected, rc(eq, 'pdk', 'type', 'deb')]) self.assert_equals(wrapper, actual)
def parse_term(self, lex): # this method does most of the heavy listing. condition = ac([]) conditions = condition.conditions # optional first word is a package name token_type, dummy = lex.peek() if token_type == 'word': dummy, name = lex.next() conditions.append(rc(eq, 'pdk', 'name', name)) # followed by an optional () containing 1 or more version relations token_type, dummy = lex.peek() if token_type == '(': self.assert_type(lex, '(') while 1: rel_type, op_func = self.parse_op(lex) version_str = self.assert_type(lex, 'word') version = self.version_class(version_str) conditions.append(rel_type(op_func, 'pdk', 'version', version)) token_type, dummy = lex.peek() if token_type == ')': self.assert_type(lex, ')') break # followed by an optional [] containing 1 or more arch conditions # These can be marked with ! meaning not. They must all be marked # or unmarked with !. token_type, dummy = lex.peek() if token_type == '[': self.assert_type(lex, '[') or_condition = oc([]) or_conditions = or_condition.conditions token_type, dummy = lex.peek() if token_type == '!': invert_mode = True else: invert_mode = False while 1: if invert_mode: self.assert_type(lex, '!') arch = self.assert_type(lex, 'word') domain = self.package_type.type_string or_conditions.append(rc(eq, domain, 'arch', arch)) token_type, dummy = lex.peek() if token_type == ']': self.assert_type(lex, ']') break if invert_mode: arch_condition = notc(or_condition) else: arch_condition = or_condition conditions.append(arch_condition) # followed by an optional {} containing 0 or more arbitrary # relations. token_type, dummy = lex.peek() if token_type == '{': self.assert_type(lex, '{') and_condition = ac([]) and_conditions = and_condition.conditions while 1: pred_str = self.assert_type(lex, 'word') if ':' in pred_str: domain, predicate = pred_str.split(':', 1) else: domain = 'pdk' predicate = pred_str rel_type, op_func = self.parse_op(lex) target = self.assert_type(lex, 'word') and_conditions.append( rel_type(op_func, domain, predicate, target)) token_type, dummy = lex.peek() if token_type == '}': self.assert_type(lex, '}') break conditions.append(and_condition) return condition
def parse_term(self, lex): # this method does most of the heavy listing. condition = ac([]) conditions = condition.conditions # optional first word is a package name token_type, dummy = lex.peek() if token_type == 'word': dummy, name = lex.next() conditions.append(rc(eq, 'pdk', 'name', name)) # followed by an optional () containing 1 or more version relations token_type, dummy = lex.peek() if token_type == '(': self.assert_type(lex, '(') while 1: rel_type, op_func = self.parse_op(lex) version_str = self.assert_type(lex, 'word') version = self.version_class(version_str) conditions.append(rel_type(op_func, 'pdk', 'version', version)) token_type, dummy = lex.peek() if token_type == ')': self.assert_type(lex, ')') break # followed by an optional [] containing 1 or more arch conditions # These can be marked with ! meaning not. They must all be marked # or unmarked with !. token_type, dummy = lex.peek() if token_type == '[': self.assert_type(lex, '[') or_condition = oc([]) or_conditions = or_condition.conditions token_type, dummy = lex.peek() if token_type == '!': invert_mode = True else: invert_mode = False while 1: if invert_mode: self.assert_type(lex, '!') arch = self.assert_type(lex, 'word') domain = self.package_type.type_string or_conditions.append(rc(eq, domain, 'arch', arch)) token_type, dummy = lex.peek() if token_type == ']': self.assert_type(lex, ']') break if invert_mode: arch_condition = notc(or_condition) else: arch_condition = or_condition conditions.append(arch_condition) # followed by an optional {} containing 0 or more arbitrary # relations. token_type, dummy = lex.peek() if token_type == '{': self.assert_type(lex, '{') and_condition = ac([]) and_conditions = and_condition.conditions while 1: pred_str = self.assert_type(lex, 'word') if ':' in pred_str: domain, predicate = pred_str.split(':', 1) else: domain = 'pdk' predicate = pred_str rel_type, op_func = self.parse_op(lex) target = self.assert_type(lex, 'word') and_conditions.append(rel_type(op_func, domain, predicate, target)) token_type, dummy = lex.peek() if token_type == '}': self.assert_type(lex, '}') break conditions.append(and_condition) return condition
def test_not(self): condition = rules.notc(self.name_condition) assert not condition.evaluate(self.a1) assert not condition.evaluate(self.a2) assert condition.evaluate(self.b1) assert condition.evaluate(self.b2)