Segfault-Inc / Multicorn

Data Access Library
https://multicorn.org/
PostgreSQL License
700 stars 145 forks source link

pytest 2.7 failure: TypeError: an integer is required #112

Closed df7cb closed 9 years ago

df7cb commented 9 years ago

Hi,

the Debian package build for multicorn in unstable is failing with this pytest error:

   dh_auto_test -O--buildsystem=pybuild
I: pybuild base:170: cd /srv/projects/postgresql/multicorn/postgresql-multicorn/.pybuild/pythonX.Y_2.7/build; python2.7 -m pytest 
=============================== test session starts ================================
platform linux2 -- Python 2.7.10 -- py-1.4.30 -- pytest-2.7.2
rootdir: /srv/projects/postgresql/multicorn/postgresql-multicorn, inifile: setup.cfg
collected 7 items 

multicorn/fsfdw/test.py F..FFF.

===================================== FAILURES =====================================
________________________________ test_docutils_meta ________________________________

    @functools.wraps(function)
    def wrapper():
        directory = tempfile.mkdtemp()
        try:
>           return function(directory)

multicorn/fsfdw/test.py:28: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

tempdir = '/home/cbe/tmp/tmp8KIVQV'

    @with_tempdir
    def test_docutils_meta(tempdir):
        def counting(filename):
            counting.n_calls += 1
            return extract_meta(filename)
        counting.n_calls = 0
        wrapper = mtime_lru_cache(counting, max_size=2)
        def extract(filename):
            return wrapper(os.path.join(tempdir, filename))
        rest_1 = '''
    The main title
    ==============

    Second title
    ------------

    :Author: Me

    Content
    '''
        meta_1 = {'title': 'The main title', 'subtitle': 'Second title',
                  'author': 'Me'}
        rest_2 = '''
    First title
    ===========

    :Author: Myself
    :Summary:
        Lorem ipsum
        dolor sit amet

    Not a subtitle
    --------------

    Content
    '''
        meta_2 = {'title': 'First title', 'author': 'Myself',
                  'summary': 'Lorem ipsum\ndolor sit amet'}
        def write(filename, content):
            with open(os.path.join(tempdir, filename), 'w') as file_obj:
                file_obj.write(content)
        write('first.rst', rest_1)
        write('second.rst', rest_2)
        assert counting.n_calls == 0
        assert extract('first.rst') == meta_1
        assert counting.n_calls == 1
        assert extract('first.rst') == meta_1  # cached
        assert counting.n_calls == 1
        assert extract('second.rst') == meta_2
        assert counting.n_calls == 2
        write('third.rst', rest_1)
        assert extract('third.rst') == meta_1  # Exceeds the cache size
        assert counting.n_calls == 3
        write('third.rst', rest_2)
>       assert extract('third.rst') == meta_2
E       assert {'author': 'M...e main title'} == {'author': 'My...'First title'}
E         Differing items:
E         {'title': 'The main title'} != {'title': 'First title'}
E         {'author': 'Me'} != {'author': 'Myself'}
E         Left contains more items:
E         {'subtitle': u'Second title'}
E         Right contains more items:
E         {'summary': 'Lorem ipsum\ndolor sit amet'}
E         Use -v to get the full diff

multicorn/fsfdw/test.py:361: AssertionError
__________________________________ test_get_items __________________________________

    @functools.wraps(function)
    def wrapper():
        directory = tempfile.mkdtemp()
        try:
>           return function(directory)

multicorn/fsfdw/test.py:28: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
multicorn/fsfdw/test.py:191: in test_get_items
    text.create(category='lipsum', num='4', name='foo').write('FOO')
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <multicorn.fsfdw.structuredfs.Item object at 0x7ff57a8cb390>, fd = 'FOO'

    def write(self, fd=None):
        if fd is None:
            fd = self.open(False)
>       os.ftruncate(fd, 0)
E       TypeError: an integer is required

multicorn/fsfdw/structuredfs.py:265: TypeError
________________________________ test_optimizations ________________________________

    @functools.wraps(function)
    def wrapper():
        directory = tempfile.mkdtemp()
        try:
>           return function(directory)

multicorn/fsfdw/test.py:28: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
multicorn/fsfdw/test.py:256: in test_optimizations
    create(cat='lipsum', org='a', name='foo', id='1')
multicorn/fsfdw/test.py:246: in create
    item.write(content)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <multicorn.fsfdw.structuredfs.Item object at 0x7ff57a9384d0>
fd = 'lipsum/a_foo/1'

    def write(self, fd=None):
        if fd is None:
            fd = self.open(False)
>       os.ftruncate(fd, 0)
E       TypeError: an integer is required

multicorn/fsfdw/structuredfs.py:265: TypeError
____________________________________ test_items ____________________________________

    @functools.wraps(function)
    def wrapper():
        directory = tempfile.mkdtemp()
        try:
>           return function(directory)

multicorn/fsfdw/test.py:28: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
multicorn/fsfdw/test.py:154: in test_items
    text.create(category='lipsum', num='5', name='bar').write('BAR')
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <multicorn.fsfdw.structuredfs.Item object at 0x7ff57a82de50>, fd = 'BAR'

    def write(self, fd=None):
        if fd is None:
            fd = self.open(False)
>       os.ftruncate(fd, 0)
E       TypeError: an integer is required

multicorn/fsfdw/structuredfs.py:265: TypeError
================== 4 failed, 3 passed, 1 warnings in 0.29 seconds ==================
E: pybuild pybuild:262: test: plugin distutils failed with: exit code=1: cd /srv/projects/postgresql/multicorn/postgresql-multicorn/.pybuild/pythonX.Y_2.7/build; python2.7 -m pytest 
dh_auto_test: pybuild --test --test-pytest -i python{version} -p 2.7 --dir . returned exit code 13
debian/rules:8: recipe for target 'build' failed
make: *** [build] Error 25

(Previously for jessie "python2.7 -m unittest discover -v" was tried which works; now on unstable/stretch, pytest fails.)

I tried to make sense of the "fd" error, the problem is that "BAR" is passed where actually a file descriptor is expected. I'm not sure how this is supposed to work, hence only a bug report and not a patch, sorry.

(This was first reported as https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=795590, though that doesn't mention the "assert author" problem.)

rdunklau commented 9 years ago

Sorry, this slipped by for so long. It turns out, I didn't event remember those tests existed. The structured fs is primarily tested through the PostgreSQL test API: make installcheck, which will run the tests in sql/python_version.

I'm a bit suprised the tests even worked in the first place, at least for the past couple years !