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

Converted autogen doctests to Python syntax #26

Merged
merged 5 commits into from
Jul 31, 2017
Merged

Conversation

defeo
Copy link
Member

@defeo defeo commented Jul 30, 2017

Item 3 in #4

import doctest

path = os.path.dirname(__file__)
if path:
os.chdir(path)
os.chdir('..')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one particularly bugs me. Why were we chdir'ing before?

@videlec
Copy link
Collaborator

videlec commented Jul 31, 2017

autogen is not a valid Python module (you would have to modify the Python path). I do not know how to properly use doctest for it. Are you able to run the doctests?

@defeo
Copy link
Member Author

defeo commented Jul 31, 2017

All the doctests pass on my machine (both Py2 and Py3). I'm just trying to convince Travis to run them. I tried modifying sys.path, to no avail. I'd have to reproduce the problem on my machine, first.

@videlec
Copy link
Collaborator

videlec commented Jul 31, 2017

I will try on mine...

@videlec
Copy link
Collaborator

videlec commented Jul 31, 2017

I got

$ python tests/rundoctest.py 
Traceback (most recent call last):
  File "tests/rundoctest.py", line 6, in <module>
    import autogen
ModuleNotFoundError: No module named 'autogen'

which I believe is normal since autogen is not a Python module available from the Python path...

@defeo
Copy link
Member Author

defeo commented Jul 31, 2017

Finally! Test pass. The sys.path fix is a bit hacky. If you have a better idea, feel free to implement.

Copy link
Collaborator

@videlec videlec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my only objection.

@@ -8,12 +8,18 @@
path = os.path.dirname(__file__)
if path:
os.chdir(path)
os.chdir('..')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is dangerous! It will change the behavior of import cypari2... you would better first test cypari2 as it used to be and in a second time, go to the appropriate directory and doctest autogen.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would it change the behavior of import cypari2?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because you have a cypari2 repository in ../

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current version of rundoctest is doctesting the installed cypari2.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os.chdir does not change the python module search path, and the search path for a script run with python script.py does not contain ..

The incriminated line would rather be the following one, that adds the cypari2 directory to sys.path. But it only adds that to the end of sys.path, so it does not take precedence over the installed cypari2.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

autogen.generator needs to read cypari2/paridecl.pxd and cypari2/declinl.pxi in order to run doctests, so it fails if we do not chdir.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I run python test/rundoctest.py in a freshly cloned repo without installing I get

Traceback (most recent call last):
  File "tests/rundoctest.py", line 5, in <module>
    import cypari2
ModuleNotFoundError: No module named 'cypari2'

Again, that's because . is not in sys.path if you run python script.py.

Isn't that enough for an error message? Why would you want a tailored message?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok right. The message is good enough.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you should at least replace .. by os.path.pardir that is more robust.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

@videlec
Copy link
Collaborator

videlec commented Jul 31, 2017

I would like

import cypari2

to be replaced by

try:
    import cypari2
except ImportError:
    raise ValueError('cypari2 must be installed in order to test it')

@defeo
Copy link
Member Author

defeo commented Jul 31, 2017

Done. If you're happy with it, feel free to merge.

@videlec videlec merged commit 17724ff into master Jul 31, 2017
@jdemeyer jdemeyer deleted the autogen_doctests branch August 22, 2017 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants