def test_name_version(self): actual = compile_debish('apache (=2.0-1)', deb, None) expected = ac([rc(eq, 'pdk', 'name', 'apache'), rc(eq, 'pdk', 'version', DebianVersion('2.0-1'))]) wrapper = ac([expected, rc(eq, 'pdk', 'type', 'deb')]) self.assert_equals(wrapper, actual)
def test_or(self): actual = compile_debish('apache | apache2', None, None) expected = oc([ ac([rc(eq, 'pdk', 'name', 'apache')]), ac([rc(eq, 'pdk', 'name', 'apache2')]) ]) self.assert_equals(expected, actual)
def test_read_write_and_or(self): os.system(''' cat >a.xml <<EOF <?xml version="1.0" encoding="utf-8"?> <component> <contents> <deb> <or> <and> <name>a</name> <arch>b</arch> </and> <name>c</name> </or> <my.some>value</my.some> </deb> </contents> </component> EOF cp a.xml b.xml ''') desc = ComponentDescriptor('a.xml') deb_ref = desc.contents[0] expected = rules.ac([ rules.oc([ rules.ac([ rules.rc(eq, 'pdk', 'name', 'a'), rules.rc(eq, 'pdk', 'arch', 'b') ]), rules.rc(eq, 'pdk', 'name', 'c') ]), rules.rc(eq, 'my', 'some', 'value') ]) expected = PhantomConditionWrapper(expected, deb, None) self.assert_equals_long(expected, deb_ref.reference.condition) desc.write() self.assert_equals_long(open('b.xml').read(), open('a.xml').read())
def test_and_or_condition(self): first = rules.ac([1, 2, 3]) same_as_first = rules.ac([1, 2, 3]) second = rules.oc([1, 2, 3]) assert first == same_as_first assert second != first assert hash(first) == hash(same_as_first)
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_term_with_blob_id(self): actual = compile_debish('apache (=2.0-1)', deb, 'sha-1:aaa') expected = ac([rc(eq, 'pdk', 'name', 'apache'), rc(eq, 'pdk', 'version', DebianVersion('2.0-1'))]) wrapper = ac([rc(eq, 'pdk', 'blob-id', 'sha-1:aaa'), expected, rc(eq, 'pdk', 'type', 'deb')]) self.assert_equals(wrapper, actual)
def test_name_version(self): actual = compile_debish('apache (=2.0-1)', deb, None) expected = ac([ rc(eq, 'pdk', 'name', 'apache'), rc(eq, 'pdk', 'version', DebianVersion('2.0-1')) ]) wrapper = ac([expected, rc(eq, 'pdk', 'type', 'deb')]) self.assert_equals(wrapper, actual)
def test_comparable(self): fields = rules.ac([('pdk', 'name', 'apache')]) refa1 = PackageStanza(deb, 'sha-1:aaa', fields, []) refa2 = PackageStanza(deb, 'sha-1:aaa', fields, []) refb = PackageStanza(deb, 'sha-1:aaa', rules.ac([('pdk', 'name', 'xsok')]), []) assert refa1 == refa2 assert refa1 < refb
def test_name_arch(self): actual = compile_debish('apache [i386 amd64]', deb, None) expected = ac([ rc(eq, 'pdk', 'name', 'apache'), 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_name_other(self): actual = compile_debish('apache {a:b = c dd:ee>=fgh i=j}', deb, None) expected = ac([rc(eq, 'pdk', 'name', 'apache'), ac([rc(eq, 'a', 'b', 'c'), rc(ge, 'dd', 'ee', 'fgh'), rc(eq, 'pdk', 'i', 'j')])]) wrapper = ac([expected, rc(eq, 'pdk', 'type', 'deb')]) self.assert_equals(wrapper, actual)
def test_term_with_blob_id(self): actual = compile_debish('apache (=2.0-1)', deb, 'sha-1:aaa') expected = ac([ rc(eq, 'pdk', 'name', 'apache'), rc(eq, 'pdk', 'version', DebianVersion('2.0-1')) ]) wrapper = ac([ rc(eq, 'pdk', 'blob-id', 'sha-1:aaa'), expected, rc(eq, 'pdk', 'type', 'deb') ]) self.assert_equals(wrapper, actual)
def test_name_other(self): actual = compile_debish('apache {a:b = c dd:ee>=fgh i=j}', deb, None) expected = ac([ rc(eq, 'pdk', 'name', 'apache'), ac([ rc(eq, 'a', 'b', 'c'), rc(ge, 'dd', 'ee', 'fgh'), rc(eq, 'pdk', 'i', 'j') ]) ]) wrapper = ac([expected, rc(eq, 'pdk', 'type', 'deb')]) self.assert_equals(wrapper, actual)
def test_untyped_version(self): actual = compile_debish('apache (=2.0-1)', None, None) expected = ac([ rc(eq, 'pdk', 'name', 'apache'), rc(eq, 'pdk', 'version', '2.0-1') ]) self.assert_equals(expected, actual)
def test_get_srpm_child_condition(self): version = RPMVersion(version_string='1-2') apache_srpm = MockPackage('apache', version, srpm, 'sha-1:aaa') expected = rules.ac([ rules.rc(eq, 'pdk', 'source-rpm', 'apache-1-2.src.rpm'), rules.rc(eq, 'pdk', 'type', 'rpm') ]) self.assert_equals(expected, get_srpm_child_condition(apache_srpm))
def test_get_general_condition(self): version = DebianVersion('1-2') apache_dsc = MockPackage('apache', version, dsc, 'sha-1:aaa') sp_version = DebianVersion('1-2') extra = {('pdk', 'sp-name'): 'one', ('pdk', 'sp-version'): sp_version, ('deb', 'arch'): 'i386'} apache_deb = MockPackage('apache', '1-2', deb, 'sha-1:aaa', extra) expected = rules.ac([ rules.rc(eq, 'pdk', 'name', 'apache'), rules.rc(eq, 'pdk', 'version', version) ]) self.assert_equals(expected, get_general_condition(apache_dsc)) expected = rules.ac([ rules.rc(eq, 'pdk', 'name', 'apache'), rules.rc(eq, 'pdk', 'version', version), rules.rc(eq, 'pdk', 'arch', 'i386') ]) self.assert_equals(expected, get_general_condition(apache_deb))
def test_get_srpm_child_condition(self): version = RPMVersion(version_string = '1-2') apache_srpm = MockPackage('apache', version, srpm, 'sha-1:aaa') expected = rules.ac([ rules.rc(eq, 'pdk', 'source-rpm', 'apache-1-2.src.rpm'), rules.rc(eq, 'pdk', 'type', 'rpm') ]) self.assert_equals(expected, get_srpm_child_condition(apache_srpm))
def test_field_lookups(self): condition = rules.ac([rules.rc(eq, 'pdk', 'name', 'apache')]) ref = PackageStanza(deb, 'sha-1:aaa', condition, []) assert ('pdk', 'name') in ref assert ('pdk', 'version') not in ref self.assert_equal('apache', ref[('pdk', 'name')]) self.assert_equal('apache', ref.name) self.assert_equal('', ref.version) self.assert_equal('', ref.arch)
def test_get_dsc_child_condition(self): version = DebianVersion('1-2') apache_dsc = MockPackage('apache', version, dsc, 'sha-1:aaa') type_condition = rules.oc([ rules.rc(eq, 'pdk', 'type', 'deb'), rules.rc(eq, 'pdk', 'type', 'udeb')]) expected = rules.ac([ rules.rc(eq, 'pdk', 'sp-name', 'apache'), rules.rc(eq, 'pdk', 'sp-version', '1-2'), type_condition ]) self.assert_equals(expected, get_dsc_child_condition(apache_dsc))
def test_get_deb_child_condition(self): sp_version = DebianVersion('1-2') extra = {('pdk', 'sp-name'): 'one', ('pdk', 'sp-version'): sp_version} apache_deb = MockPackage('apache', '1', deb, 'sha-1:aaa', extra) expected = rules.ac([ rules.rc(eq, 'pdk', 'name', 'one'), rules.rc(eq, 'pdk', 'version', '1-2'), rules.rc(eq, 'pdk', 'type', 'dsc') ]) self.assert_equals(expected, get_deb_child_condition(apache_deb))
def test_get_rpm_child_condition(self): version = RPMVersion(version_string = '1-2') extras = {('pdk', 'source-rpm'): 'apache.src.rpm'} apache_rpm = MockPackage('apache', version, rpm, 'sha-1:aaa', extras = extras) expected = rules.ac([ rules.rc(eq, 'pdk', 'filename', 'apache.src.rpm'), rules.rc(eq, 'pdk', 'type', 'srpm') ]) self.assert_equals(expected, get_rpm_child_condition(apache_rpm))
def test_get_child_condition(self): sp_version = DebianVersion('1-3') extra = {('pdk', 'sp-name'): 'apache', ('pdk', 'sp-version'): sp_version, ('deb', 'arch'): 'i386'} apache_deb = MockPackage('apache', '1-2', deb, 'sha-1:aaa', extra) ref_condition = rules.ac([rules.rc(eq, 'pdk', 'name', 'apache')]) apache_ref = PackageStanza(deb, 'sha-1:aaa', ref_condition, []) parent_condition = rules.ac([ apache_ref.reference.condition, rules.rc(eq, 'pdk', 'version', DebianVersion('1-2')) ]) child_condition = get_deb_child_condition(apache_deb) expected_rule = rules.oc([child_condition, parent_condition]) expected_key_info = ('pdk', 'name', 'apache') actual_rule, actual_key_info = get_child_condition(apache_deb, apache_ref) self.assert_equals(expected_rule, actual_rule) self.assert_equals(expected_key_info, actual_key_info)
def test_get_dsc_child_condition(self): version = DebianVersion('1-2') apache_dsc = MockPackage('apache', version, dsc, 'sha-1:aaa') type_condition = rules.oc([ rules.rc(eq, 'pdk', 'type', 'deb'), rules.rc(eq, 'pdk', 'type', 'udeb') ]) expected = rules.ac([ rules.rc(eq, 'pdk', 'sp-name', 'apache'), rules.rc(eq, 'pdk', 'sp-version', '1-2'), type_condition ]) self.assert_equals(expected, get_dsc_child_condition(apache_dsc))
def test_get_child_condition(self): sp_version = DebianVersion('1-3') extra = { ('pdk', 'sp-name'): 'apache', ('pdk', 'sp-version'): sp_version, ('deb', 'arch'): 'i386' } apache_deb = MockPackage('apache', '1-2', deb, 'sha-1:aaa', extra) ref_condition = rules.ac([rules.rc(eq, 'pdk', 'name', 'apache')]) apache_ref = PackageStanza(deb, 'sha-1:aaa', ref_condition, []) parent_condition = rules.ac([ apache_ref.reference.condition, rules.rc(eq, 'pdk', 'version', DebianVersion('1-2')) ]) child_condition = get_deb_child_condition(apache_deb) expected_rule = rules.oc([child_condition, parent_condition]) expected_key_info = ('pdk', 'name', 'apache') actual_rule, actual_key_info = get_child_condition( apache_deb, apache_ref) self.assert_equals(expected_rule, actual_rule) self.assert_equals(expected_key_info, actual_key_info)
def test_get_general_condition(self): version = DebianVersion('1-2') apache_dsc = MockPackage('apache', version, dsc, 'sha-1:aaa') sp_version = DebianVersion('1-2') extra = { ('pdk', 'sp-name'): 'one', ('pdk', 'sp-version'): sp_version, ('deb', 'arch'): 'i386' } apache_deb = MockPackage('apache', '1-2', deb, 'sha-1:aaa', extra) expected = rules.ac([ rules.rc(eq, 'pdk', 'name', 'apache'), rules.rc(eq, 'pdk', 'version', version) ]) self.assert_equals(expected, get_general_condition(apache_dsc)) expected = rules.ac([ rules.rc(eq, 'pdk', 'name', 'apache'), rules.rc(eq, 'pdk', 'version', version), rules.rc(eq, 'pdk', 'arch', 'i386') ]) self.assert_equals(expected, get_general_condition(apache_deb))
def test_get_rpm_child_condition(self): version = RPMVersion(version_string='1-2') extras = {('pdk', 'source-rpm'): 'apache.src.rpm'} apache_rpm = MockPackage('apache', version, rpm, 'sha-1:aaa', extras=extras) expected = rules.ac([ rules.rc(eq, 'pdk', 'filename', 'apache.src.rpm'), rules.rc(eq, 'pdk', 'type', 'srpm') ]) self.assert_equals(expected, get_rpm_child_condition(apache_rpm))
def set_up(self): super(ConditionsAndRulesFixture, self).set_up() self.name_condition = rules.rc(eq, 'pdk', 'name', 'a') self.version_condition = rules.rc(eq, 'pdk', 'version', '1') self.and_condition = rules.ac([self.name_condition, self.version_condition]) self.or_condition = rules.oc([self.name_condition, self.version_condition]) self.a1 = MockPackage('a', '1', deb) self.a2 = MockPackage('a', '2', deb) self.b1 = MockPackage('b', '1', deb) self.b2 = MockPackage('b', '2', deb) self.c = MockPackage('c', '1', dsc, lang = 'de') self.d = MockPackage('d', '1', dsc, lang = 'en') self.a1.complement.append(self.c) self.a2.complement.append(self.d)
def set_up(self): super(ConditionsAndRulesFixture, self).set_up() self.name_condition = rules.rc(eq, 'pdk', 'name', 'a') self.version_condition = rules.rc(eq, 'pdk', 'version', '1') self.and_condition = rules.ac( [self.name_condition, self.version_condition]) self.or_condition = rules.oc( [self.name_condition, self.version_condition]) self.a1 = MockPackage('a', '1', deb) self.a2 = MockPackage('a', '2', deb) self.b1 = MockPackage('b', '1', deb) self.b2 = MockPackage('b', '2', deb) self.c = MockPackage('c', '1', dsc, lang='de') self.d = MockPackage('d', '1', dsc, lang='en') self.a1.complement.append(self.c) self.a2.complement.append(self.d)
def wrap_condition(self, condition): '''Wrap the condition to verify the package_type and blob_id. Return the original condition of neither are given. ''' if self.blob_id or self.package_type: wrapper = ac([]) conditions = wrapper.conditions if self.blob_id: conditions.append(rc(eq, 'pdk', 'blob-id', self.blob_id)) conditions.append(condition) if self.package_type: if self.package_type.format_string == 'unknown': role_string = self.package_type.role_string conditions.append(rc(eq, 'pdk', 'role', role_string)) else: type_string = self.package_type.type_string conditions.append(rc(eq, 'pdk', 'type', type_string)) return wrapper else: return condition
def test_build_general_debish_ref(self): actual = compile_debish('apache', src, None) expected = ac([rc(eq, 'pdk', 'name', 'apache')]) wrapper = ac([expected, rc(eq, 'pdk', 'role', 'source')]) self.assert_equals(wrapper, actual)
def __init__(self, label): condition = rules.ac([('pdk', 'name', 'apache')]) PackageStanza.__init__(self, deb, None, condition, []) self.label = label self.children = []
def test_relaxed_relation(self): actual = compile_debish('apache {a:b %= c}', None, None) expected = ac( [rc(eq, 'pdk', 'name', 'apache'), ac([relrc(eq, 'a', 'b', 'c')])]) self.assert_equals(expected, actual)
def test_relaxed_relation(self): actual = compile_debish('apache {a:b %= c}', None, None) expected = ac([rc(eq, 'pdk', 'name', 'apache'), ac([relrc(eq, 'a', 'b', 'c')])]) self.assert_equals(expected, actual)
def test_name_only(self): actual = compile_debish('apache', None, None) expected = ac([rc(eq, 'pdk', 'name', 'apache')]) self.assert_equals(expected, 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_untyped_version(self): actual = compile_debish('apache (=2.0-1)', None, None) expected = ac([rc(eq, 'pdk', 'name', 'apache'), rc(eq, 'pdk', 'version', '2.0-1')]) self.assert_equals(expected, actual)
def test_star2(self): actual = compile_debish('** apache | apache2', None, None) expected = star2c(oc([ac([rc(eq, 'pdk', 'name', 'apache')]), ac([rc(eq, 'pdk', 'name', 'apache2')])])) self.assert_equals(expected, actual)