示例#1
0
def test_fromxml_url():
    # check internet connection
    try:
        url = 'http://raw.githubusercontent.com/petl-developers/petl/master/.pydevproject'
        urlopen(url)
    except Exception as e:
        print('SKIP test_fromxml_url: %s' % e, file=sys.stderr)
    else:
        actual = fromxml(url, 'pydev_property', {'name': ( '.', 'name'), 'prop': '.'})
        assert nrows(actual) > 0
        expect = fromxml('.pydevproject', 'pydev_property', {'name': ( '.', 'name'), 'prop': '.'})
        ieq(expect, actual)
示例#2
0
def test_fromxml_url():
    # check internet connection
    try:
        url = 'http://raw.githubusercontent.com/petl-developers/petl/master/petl/test/resources/test.xml'
        urlopen(url)
        import pkg_resources
        filename = pkg_resources.resource_filename('petl', 'test/resources/test.xml')
    except Exception as e:
        pytest.skip('SKIP test_fromxml_url: %s' % e)
    else:
        actual = fromxml(url, 'pydev_property', {'name': ( '.', 'name'), 'prop': '.'})
        assert nrows(actual) > 0
        expect = fromxml(filename, 'pydev_property', {'name': ( '.', 'name'), 'prop': '.'})
        ieq(expect, actual)
示例#3
0
文件: sources.py 项目: DeanWay/petl
 def open(self, mode='r'):
     if not mode.startswith('r'):
         raise ArgumentError('source is read-only')
     f = urlopen(*self.args, **self.kwargs)
     try:
         yield f
     finally:
         f.close()
示例#4
0
文件: sources.py 项目: juarezr/petl
 def open(self, mode='r'):
     if not mode.startswith('r'):
         raise ArgumentError('source is read-only')
     f = urlopen(*self.args, **self.kwargs)
     try:
         yield f
     finally:
         f.close()
示例#5
0
文件: sources.py 项目: juarezr/petl
 def open(self, mode='r'):
     if self.remote:
         if not mode.startswith('r'):
             raise ArgumentError('source is read-only')
         filehandle = urlopen(self.filename)
     else:
         filehandle = self.filename
     source = bz2.BZ2File(filehandle, mode, **self.kwargs)
     try:
         yield source
     finally:
         source.close()
示例#6
0
文件: sources.py 项目: alimanfoo/petl
 def open(self, mode='r'):
     if self.remote:
         if not mode.startswith('r'):
             raise ArgumentError('source is read-only')
         filehandle = urlopen(self.filename)
     else:
         filehandle = self.filename
     source = bz2.BZ2File(filehandle, mode, **self.kwargs)
     try:
         yield source
     finally:
         source.close()
示例#7
0
</tr>
<tr>
<td>c</td>
<td style='text-align: right'>3</td>
</tr>
</tbody>
</table>"""
    f = NamedTemporaryFile(delete=False, mode='wt')
    f.write(data)
    f.close()

    actual = fromxml(f.name, './/tr', ('th', 'td'))
    print(look(actual))
    expect = (('foo', 'bar'), ('a', '2'), ('b', '1'), ('c', '3'))
    ieq(expect, actual)
    ieq(expect, actual)  # verify can iterate twice


url = 'http://feeds.bbci.co.uk/news/rss.xml'
# check internet connection
try:
    urlopen(url)
except Exception as e:
    print('SKIP test_fromxml_url: %s' % e, file=sys.stderr)
else:

    def test_fromxml_url():

        tbl = fromxml(url, './/item', 'title')
        assert nrows(tbl) > 0
示例#8
0
文件: test_xml.py 项目: DeanWay/petl
<td style='text-align: right'>3</td>
</tr>
</tbody>
</table>"""
    f = NamedTemporaryFile(delete=False, mode='wt')
    f.write(data)
    f.close()

    actual = fromxml(f.name, './/tr', ('th', 'td'))
    print(look(actual))
    expect = (('foo', 'bar'),
              ('a', '2'),
              ('b', '1'),
              ('c', '3'))
    ieq(expect, actual)
    ieq(expect, actual)  # verify can iterate twice


url = 'http://feeds.bbci.co.uk/news/rss.xml'
# check internet connection
try:
    urlopen(url)
except Exception as e:
    print('SKIP test_fromxml_url: %s' % e, file=sys.stderr)
else:

    def test_fromxml_url():

            tbl = fromxml(url, './/item', 'title')
            assert nrows(tbl) > 0