Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

continued failing doctests in libpysal.io #145

Closed
jGaboardi opened this issue Mar 14, 2019 · 2 comments

Comments

@jGaboardi
Copy link
Member

commented Mar 14, 2019

Following up with #144, there were 25+ failing doctests within libpysal/io/. Below the final two are listed with tracebacks. As with #144, it is still not clear how we could have missed these and why they hadn't been run in Travis until several days ago.


  • From what I can tell this is an issue where the doctest was written for python 2 and is just now getting run in python 3. SOLVED
======================================================================
FAIL: Doctest: libpysal.io.util.shapefile._unpackDict
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/pysal/libpysal/miniconda/envs/test-env/lib/python3.5/doctest.py", line 2190, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for libpysal.io.util.shapefile._unpackDict
  File "/home/travis/build/pysal/libpysal/libpysal/io/util/shapefile.py", line 117, in _unpackDict
----------------------------------------------------------------------
File "/home/travis/build/pysal/libpysal/libpysal/io/util/shapefile.py", line 141, in libpysal.io.util.shapefile._unpackDict
Failed example:
    _unpackDict(UHEADERSTRUCT, libpysal.io.open(libpysal.examples.get_path('10740.shx'),'rb')) == {'BBOX Xmax': -105.29012, 'BBOX Ymax': 36.219799000000002, 'BBOX Mmax': 0.0, 'BBOX Zmin': 0.0, 'BBOX Mmin': 0.0, 'File Code': 9994, 'BBOX Ymin': 34.259672000000002, 'BBOX Xmin': -107.62651, 'Unused0': 0, 'Unused1': 0, 'Unused2': 0, 'Unused3': 0, 'Unused4': 0, 'Version': 1000, 'BBOX Zmax': 0.0, 'Shape Type': 5, 'File Length': 830}
Exception raised:
    Traceback (most recent call last):
      File "/home/travis/build/pysal/libpysal/miniconda/envs/test-env/lib/python3.5/doctest.py", line 1321, in __run
        compileflags, 1), test.globs)
      File "<doctest libpysal.io.util.shapefile._unpackDict[1]>", line 1, in <module>
        _unpackDict(UHEADERSTRUCT, libpysal.io.open(libpysal.examples.get_path('10740.shx'),'rb')) == {'BBOX Xmax': -105.29012, 'BBOX Ymax': 36.219799000000002, 'BBOX Mmax': 0.0, 'BBOX Zmin': 0.0, 'BBOX Mmin': 0.0, 'File Code': 9994, 'BBOX Ymin': 34.259672000000002, 'BBOX Xmin': -107.62651, 'Unused0': 0, 'Unused1': 0, 'Unused2': 0, 'Unused3': 0, 'Unused4': 0, 'Version': 1000, 'BBOX Zmax': 0.0, 'Shape Type': 5, 'File Length': 830}
      File "/home/travis/build/pysal/libpysal/libpysal/io/util/shapefile.py", line 148, in _unpackDict
        fileObj.read(struct['size']))
    TypeError: a bytes-like object is required, not 'list'

  • When attempting to open a .shx file, pyShpIO is called which throws an error because an .shx is not a .shp. This doesn't not seem like a bug, because the .shp is a base object where .shx is not. Should this test be scrapped or should we add this functionality to in the form of pyShxIO as a complement to pyShpIO and pyDbfIO. SOLVED
======================================================================
FAIL: Doctest: libpysal.io.util.shapefile.shx_file.add_record
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/pysal/libpysal/miniconda/envs/test-env/lib/python3.5/doctest.py", line 2190, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for libpysal.io.util.shapefile.shx_file.add_record
  File "/home/travis/build/pysal/libpysal/libpysal/io/util/shapefile.py", line 538, in add_record
----------------------------------------------------------------------
File "/home/travis/build/pysal/libpysal/libpysal/io/util/shapefile.py", line 571, in libpysal.io.util.shapefile.shx_file.add_record
Failed example:
    libpysal.io.open('test.shx','rb').read() == libpysal.io.open(libpysal.examples.get_path('Point.shx'),'rb').read()
Exception raised:
    Traceback (most recent call last):
      File "/home/travis/build/pysal/libpysal/miniconda/envs/test-env/lib/python3.5/doctest.py", line 1321, in __run
        compileflags, 1), test.globs)
      File "<doctest libpysal.io.util.shapefile.shx_file.add_record[7]>", line 1, in <module>
        libpysal.io.open('test.shx','rb').read() == libpysal.io.open(libpysal.examples.get_path('Point.shx'),'rb').read()
      File "/home/travis/build/pysal/libpysal/libpysal/io/iohandlers/pyShpIO.py", line 70, in __init__
        self.__open()
      File "/home/travis/build/pysal/libpysal/libpysal/io/iohandlers/pyShpIO.py", line 81, in __open
        self.dataObj = shp_file(self.dataPath)
      File "/home/travis/build/pysal/libpysal/libpysal/io/util/shapefile.py", line 242, in __init__
        self._open_shp_file()
      File "/home/travis/build/pysal/libpysal/libpysal/io/util/shapefile.py", line 275, in _open_shp_file
        self.fileObj = open(fileName + '.shp', 'rb')
    FileNotFoundError: [Errno 2] No such file or directory: 'test.shp'
@jGaboardi

This comment has been minimized.

Copy link
Member Author

commented Mar 14, 2019

jGaboardi added a commit to jGaboardi/libpysal that referenced this issue Mar 19, 2019
@jGaboardi

This comment has been minimized.

Copy link
Member Author

commented Mar 19, 2019

Both of the issue above were solved by changing libpysal.io.open to python's vanilla open.

@jGaboardi jGaboardi self-assigned this Mar 19, 2019

@jGaboardi jGaboardi closed this Mar 19, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.