Skip to content

Doc test in README.md fails due to undefined variable #264

Closed
@JamesParrott

Description

@JamesParrott

PyShp Version

3.2.1

Python Version

3.12.1 and 2.7 for Windows.

Your code

git clone --depth=1 https://github.com/GeospatialPython/pyshp .
python shapefile.py

Full stacktrace

c:\tmp>git clone --depth=1 https://github.com/GeospatialPython/pyshp .
Cloning into '.'...
remote: Enumerating objects: 80, done.
remote: Counting objects: 100% (80/80), done.
remote: Compressing objects: 100% (73/73), done.
remote: Total 80 (delta 17), reused 46 (delta 4), pack-reused 0
Receiving objects: 100% (80/80), 2.02 MiB | 966.00 KiB/s, done.
Resolving deltas: 100% (17/17), done.

c:\tmp>python --version
Python 3.12.1

c:\tmp>python shapefile.py
Running doctests...
**********************************************************************
File "README.md", line 1085, in README
Failed example:
    with open("{}.prj".format(filename), "w") as prj:
Exception raised:
    Traceback (most recent call last):
      File "C:\Users\...\AppData\Local\Programs\Python\Python312\Lib\doctest.py", line 1359, in __run
        exec(compile(example.source, filename, "single",
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "<doctest README[206]>", line 1
        with open("{}.prj".format(filename), "w") as prj:
                                                         ^
    IndentationError: expected an indented block after 'with' statement on line 1
**********************************************************************
File "README.md", line 1086, in README
Failed example:
        wkt = 'GEOGCS["WGS 84",'
Exception raised:
    Traceback (most recent call last):
      File "C:\Users\...\AppData\Local\Programs\Python\Python312\Lib\doctest.py", line 1359, in __run
        exec(compile(example.source, filename, "single",
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "<doctest README[207]>", line 1
        wkt = 'GEOGCS["WGS 84",'
    IndentationError: unexpected indent
**********************************************************************
File "README.md", line 1087, in README
Failed example:
        wkt += 'DATUM["WGS_1984",'
Exception raised:
    Traceback (most recent call last):
      File "C:\Users\...\AppData\Local\Programs\Python\Python312\Lib\doctest.py", line 1359, in __run
        exec(compile(example.source, filename, "single",
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "<doctest README[208]>", line 1
        wkt += 'DATUM["WGS_1984",'
    IndentationError: unexpected indent
**********************************************************************
File "README.md", line 1088, in README
Failed example:
        wkt += 'SPHEROID["WGS 84",6378137,298.257223563]]'
Exception raised:
    Traceback (most recent call last):
      File "C:\Users\...\AppData\Local\Programs\Python\Python312\Lib\doctest.py", line 1359, in __run
        exec(compile(example.source, filename, "single",
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "<doctest README[209]>", line 1
        wkt += 'SPHEROID["WGS 84",6378137,298.257223563]]'
    IndentationError: unexpected indent
**********************************************************************
File "README.md", line 1089, in README
Failed example:
        wkt += ',PRIMEM["Greenwich",0],'
Exception raised:
    Traceback (most recent call last):
      File "C:\Users\...\AppData\Local\Programs\Python\Python312\Lib\doctest.py", line 1359, in __run
        exec(compile(example.source, filename, "single",
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "<doctest README[210]>", line 1
        wkt += ',PRIMEM["Greenwich",0],'
    IndentationError: unexpected indent
**********************************************************************
File "README.md", line 1090, in README
Failed example:
        wkt += 'UNIT["degree",0.0174532925199433]]'
Exception raised:
    Traceback (most recent call last):
      File "C:\Users\...\AppData\Local\Programs\Python\Python312\Lib\doctest.py", line 1359, in __run
        exec(compile(example.source, filename, "single",
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "<doctest README[211]>", line 1
        wkt += 'UNIT["degree",0.0174532925199433]]'
    IndentationError: unexpected indent
**********************************************************************
File "README.md", line 1091, in README
Failed example:
        prj.write(wkt)
Exception raised:
    Traceback (most recent call last):
      File "C:\Users\...\AppData\Local\Programs\Python\Python312\Lib\doctest.py", line 1359, in __run
        exec(compile(example.source, filename, "single",
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "<doctest README[212]>", line 1
        prj.write(wkt)
    IndentationError: unexpected indent
**********************************************************************
1 items had failures:
   7 of 276 in README
***Test Failed*** 7 failures.

Other notes

An explanatory example was added to README.md for the benefit of users, that depends on an undefined variable. This addition was made with the honest goal of being helpful, but perhaps forgetting README.md is passed verbatim by shapefile.test to doctest, which runs all code snippets followed by >>>.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions