Beispiel #1
0
    def test_bad_validate(self):
        s = S('head', '', group='g', children=[
            S('item', '')
        ])

        sp = SP(head2=SP.one)
        self.assertRaises(ValueError, sp.validate, s)

        sp = SP(head=SP(item=SP.one))
        self.assertRaises(ValueError, sp.validate, s)

        sp = SP(head=SP.one)
        missing = sp.validate(s)
        self.assertDictEqual(missing, {'g': {'item': None}})
Beispiel #2
0
    def test_bad_validate(self):
        s = S('head', '', group='g', children=[S('item', '')])

        sp = SP(head2=SP.one)
        self.assertRaises(ValueError, sp.validate, s)

        sp = SP(head=SP(item=SP.one))
        self.assertRaises(ValueError, sp.validate, s)

        sp = SP(head=SP.one)
        missing = sp.validate(s)
        self.assertDictEqual(missing, {'g': {'item': None}})
Beispiel #3
0
    def test_basic_proc(self):
        proc = SP(
            title=SP.id,
            h=SP.space,
            ips=SP(
                ip=SP.one,
                port=SP.one,
            ),
            ports=SP.unique,
            nothing=SP.defaultf(42)
        )
        proc.validate(basic_ts)
        data = proc.parse(self.parsed)

        self.assertIsInstance(data['title'][0], HtmlXPathSelector)
        self.assertEqual(data['h'], u'Here is the list of some ip addresses !!!')
        self.assertListEqual(data['ports'], [u'94', u'91', u'90', u'80', u'92', u'93'])
        ips = data['ips']
        self.assertEqual(len(ips), 6)
        self.assertDictEqual(ips[0], {'ip': u'123.44.1.9', 'port': u'80'})
        self.assertEqual(data['nothing'], 42)
Beispiel #4
0
    def test_basic_proc(self):
        proc = SP(title=SP.id,
                  h=SP.space,
                  ips=SP(
                      ip=SP.one,
                      port=SP.one,
                  ),
                  ports=SP.unique,
                  nothing=SP.defaultf(42))
        proc.validate(basic_ts)
        data = proc.parse(self.parsed)

        self.assertIsInstance(data['title'][0], HtmlXPathSelector)
        self.assertEqual(data['h'],
                         u'Here is the list of some ip addresses !!!')
        self.assertListEqual(data['ports'],
                             [u'94', u'91', u'90', u'80', u'92', u'93'])
        ips = data['ips']
        self.assertEqual(len(ips), 6)
        self.assertDictEqual(ips[0], {'ip': u'123.44.1.9', 'port': u'80'})
        self.assertEqual(data['nothing'], 42)