Esempio n. 1
0
    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())
Esempio n. 2
0
 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)
Esempio n. 3
0
    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)
Esempio n. 4
0
 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)
Esempio n. 5
0
    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)
Esempio n. 6
0
 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)
Esempio n. 7
0
    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))
Esempio n. 8
0
    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))
Esempio n. 9
0
    def parse_or(self, lex):
        terms = []
        while 1:
            term = self.parse_term(lex)
            terms.append(term)
            token_type, dummy = lex.peek()
            if token_type == '|':
                self.assert_type(lex, '|')
            else:
                break

        if len(terms) == 1:
            return terms[0]
        else:
            return oc(terms)
Esempio n. 10
0
    def parse_or(self, lex):
        terms = []
        while 1:
            term = self.parse_term(lex)
            terms.append(term)
            token_type, dummy = lex.peek()
            if token_type == '|':
                self.assert_type(lex, '|')
            else:
                break

        if len(terms) == 1:
            return terms[0]
        else:
            return oc(terms)
Esempio n. 11
0
    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)
Esempio n. 12
0
    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)
Esempio n. 13
0
    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)
Esempio n. 14
0
    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())
Esempio n. 15
0
    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)
Esempio n. 16
0
    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
Esempio n. 17
0
    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
Esempio n. 18
0
 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)