def test_absolute(self):
        # don't allow exclusions in an absolute pattern
        with self.assertRaises(ValueError):
            pattern = TagPattern.parse('#foo+a-b!')

        pattern = TagPattern.parse('#foo+a!')
        self.assertTrue(pattern.is_absolute)
        self.assertTrue(pattern.match(Column.parse('#foo+a')))
        self.assertFalse(pattern.match(Column.parse('#foo')))
        self.assertFalse(pattern.match(Column.parse('#foo+a+b')))
    def test_absolute(self):
        # don't allow exclusions in an absolute pattern
        with self.assertRaises(ValueError):
            pattern = TagPattern.parse('#foo+a-b!')

        pattern = TagPattern.parse('#foo+a!')
        self.assertTrue(pattern.is_absolute)
        self.assertTrue(pattern.match(Column.parse('#foo+a')))
        self.assertFalse(pattern.match(Column.parse('#foo')))
        self.assertFalse(pattern.match(Column.parse('#foo+a+b')))
Beispiel #3
0
 def setUp(self):
     self.errors = []
     self.schema = Schema(rules=[
         SchemaRule('#sector', min_occur=1),
         SchemaRule('#affected', data_type='number')
     ],
                          callback=lambda error: self.errors.append(error))
     self.row = Row(columns=[
         Column(tag='#affected'),
         Column(tag='#sector'),
         Column(tag='#sector')
     ])
    def test_parse_attributes(self):
        # Single attribute
        specs = ['#tag+foo', '#tag +foo', ' #tag +foo   ']
        for column in [Column.parse(spec) for spec in specs]:
            column = Column.parse('#tag+foo')
            self.assertEqual('#tag', column.tag)
            self.assertEqual(['foo'], sorted(column.attributes))

        # Multiple attributes
        specs = ['#tag+foo+bar', '#tag +foo +bar', ' #tag +bar+foo   ']
        for column in [Column.parse(spec) for spec in specs]:
            self.assertEqual('#tag', column.tag)
            self.assertEqual(['bar', 'foo'], sorted(column.attributes))
    def test_parse_attributes(self):
        # Single attribute
        specs = ['#tag+foo', '#tag +foo', ' #tag +foo   ']
        for column in [Column.parse(spec) for spec in specs]:
            column = Column.parse('#tag+foo')
            self.assertEqual('#tag', column.tag)
            self.assertEqual(['foo'], sorted(column.attributes))

        # Multiple attributes
        specs = ['#tag+foo+bar', '#tag +foo +bar', ' #tag +bar+foo   ']
        for column in [Column.parse(spec) for spec in specs]:
            self.assertEqual('#tag', column.tag)
            self.assertEqual(['bar', 'foo'], sorted(column.attributes))
Beispiel #6
0
    def test_parse_invalid(self):

        # empty string
        col = Column.parse("   ")
        self.assertIsNone(col)

        # without exception
        col = Column.parse('#foo + a +b')
        self.assertTrue(col is False)

        # with exception
        with self.assertRaises(hxl.HXLException):
            col = Column.parse('#foo + a +b', use_exception=True)
    def assertRowErrors(self, row_values, errors_expected, schema_values=None, columns=None):
        """Set up a HXL row and count the errors in it"""
        errors = []

        def callback(error):
            errors.append(error)

        if schema_values is None:
            schema = hxl.schema(hxl.data(self.DEFAULT_SCHEMA), callback=callback)
        else:
            schema = hxl.schema(hxl.data(schema_values), callback=callback)

        if columns is None:
            columns = self.DEFAULT_COLUMNS

        row = Row(
            values=row_values,
            columns=[Column.parse(tag) for tag in columns]
        )

        schema.start()

        if errors_expected == 0:
            self.assertTrue(schema.validate_row(row))
        else:
            self.assertFalse(schema.validate_row(row))
        self.assertEqual(len(errors), errors_expected)
    def assertRowErrors(self,
                        row_values,
                        errors_expected,
                        schema_values=None,
                        columns=None):
        """Set up a HXL row and count the errors in it"""
        errors = []

        def callback(error):
            errors.append(error)

        if schema_values is None:
            schema = hxl.schema(hxl.data(self.DEFAULT_SCHEMA),
                                callback=callback)
        else:
            schema = hxl.schema(hxl.data(schema_values), callback=callback)

        if columns is None:
            columns = self.DEFAULT_COLUMNS

        row = Row(values=row_values,
                  columns=[Column.parse(tag) for tag in columns])

        schema.start()

        if errors_expected == 0:
            self.assertTrue(schema.validate_row(row))
        else:
            self.assertFalse(schema.validate_row(row))
        self.assertEqual(len(errors), errors_expected)
 def setUp(self):
     columns = []
     for column_number, tag in enumerate(self.TAGS):
         columns.append(Column.parse(tag))
     self.row = Row(columns=columns,
                    values=self.CONTENT,
                    row_number=self.ROW_NUMBER)
Beispiel #10
0
    def test_row_restrictions(self):
        row = Row(columns=[
            Column(tag='#x_test'),
            Column(tag='#subsector'),
            Column(tag='#x_test')
        ],
                  values=['WASH', '', ''])

        self.rule.min_occur = 1
        self._try_rule(row)

        self.rule.min_occur = 2
        self._try_rule(row, 1)

        self.rule.min_occur = None

        self.rule.max_occur = 1
        self._try_rule(row)

        self.rule.max_occur = 0
        self._try_rule(row, 1)
 def setUp(self):
     self.column = Column(tag='#tag', attributes=['foo', 'bar'])
 def test_hash(self):
     col1 = Column(tag='xxx', attributes={'b', 'c', 'a'}, header='foo')
     col2 = Column(tag='xxx', attributes={'a', 'b', 'c'}, header='bar')
     col3 = Column(tag='xxx', attributes={'b', 'c'})
     self.assertEqual(hash(col1), hash(col2))
     self.assertNotEqual(hash(col1), hash(col3))
 def test_attribute_order(self):
     TAGSPEC = '#foo+b+a+c+w+x'
     self.assertEqual(TAGSPEC, Column.parse(TAGSPEC).display_tag)
 def test_case_insensitive(self):
     column = Column(tag='Foo', attributes=['X', 'y'])
     self.assertEqual('foo', column.tag)
     self.assertEqual(set(['x', 'y']), column.attributes)
 def test_wildcard_empty_column(self):
     pattern = TagPattern.parse('*')
     untagged_column = Column(header="Foo", column_number=1)
     self.assertFalse(pattern.match(untagged_column))
Beispiel #16
0
 def test_parse_valid(self):
     col = Column.parse("#foo +a +b")
     self.assertEqual(col.tag, '#foo')
     self.assertTrue('a' in col.attributes)
     self.assertTrue('b' in col.attributes)
Beispiel #17
0
 def test_get_skip_blanks(self):
     columns = [Column.parse(tag) for tag in ['#sector', '#org', '#org']]
     row = Row(columns=columns, values=['Health', '', 'WFP'])
     # Test that row.get() returns first non-blank value
     self.assertEqual('WFP', row.get('org'))
Beispiel #18
0
 def setUp(self):
     columns = []
     for column_number, tag in enumerate(self.TAGS):
         columns.append(Column.parse(tag))
     self.row = Row(columns=columns, values=self.CONTENT, row_number=self.ROW_NUMBER)
 def test_get_skip_blanks(self):
     columns = [Column.parse(tag) for tag in ['#sector', '#org', '#org']]
     row = Row(columns=columns, values=['Health', '', 'WFP'])
     # Test that row.get() returns first non-blank value
     self.assertEqual('WFP', row.get('org'))
 def test_parse_simple(self):
     column = Column.parse('#tag')
     self.assertEqual('#tag', column.tag)
Beispiel #21
0
 def test_attribute_order(self):
     TAGSPEC = '#foo+b+a+c+w+x'
     self.assertEqual(TAGSPEC, Column.parse(TAGSPEC).display_tag)
 def test_tags(self):
     self.assertEqual([Column.parse(s).tag for s in DATA[1]],
                      self.source.tags)
 def setUp(self):
     self.column = Column(tag=TestColumn.HXL_TAG,
                          attributes=TestColumn.ATTRIBUTES,
                          header=TestColumn.HEADER_TEXT)
Beispiel #24
0
 def test_tags(self):
     self.assertEqual([Column.parse(s).tag for s in DATA[1]], self.source.tags)
Beispiel #25
0
 def test_parse_simple(self):
     column = Column.parse('#tag')
     self.assertEqual('#tag', column.tag)