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

Unittest sample : Proposal for issue #4 #57

Closed
wants to merge 28 commits into from

Conversation

vinklein
Copy link
Contributor

This pull request port some GP doctests as Python unittest.
This a solution proposal for issue #4.
A more complete but not fully working version can be found here unittest_dev.

What is your advices on this implementation ?
Comments and critics are welcome

Vincent Klein added 25 commits January 17, 2018 14:34
fix setUp and tearDown in gamma.py
'list', 'log', 'mathnf', 'contfrac', 'minim',
'minmax','modfun','modular', 'nfrootsof1',
'nfsplitting', 'norm'
prec, prime, primes, qfb, qfbclassno, qfsolve, quadray
'rootsreal', 'ser', 'subst','sumdedekind',
'sumformal', 'zeta'
add precision to factorial call
bestappr
ellanal
idealramgroups
quadray
polred
polylog
gamma
nfsplitting
rootsreal
ser
subst
Test working with 2.9.3 2.8.1.beta and snapshot versions
@videlec
Copy link
Collaborator

videlec commented Jan 17, 2018

What is the file unittest_sample used for?

@vinklein
Copy link
Contributor Author

unittest_sample is this branch, if you mean unittest_template, it's a unused file i shouldn't have commit : )

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.

I like the usage of unittest very much. Though I think that you should try harder to not compare strings but actual objects. They can not do that in PARI/GP but here we do.

galpol_installed = True
seadata_installed = True

# test extensions presence.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would propose to encapsulate these in functions has_seadata, has_galpol, has_elldata, etc that would actually be part of the cypari2 library. Perhaps as methods of Pari.



for t in testmodules:
if not ((t in require_galpol and not galpol_installed) or (t in require_seadata and not seadata_installed)):
Copy link
Collaborator

Choose a reason for hiding this comment

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

please change the condition to

(galpol_installed or t not in require_galpol) and (seadata_installed or t not in require_seadata)


for t in testmodules:
if not ((t in require_galpol and not galpol_installed) or (t in require_seadata and not seadata_installed)):
try:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Couldn't this be uniform among all the files? This try/except is a bit ugly.

@@ -0,0 +1,87 @@
import unittest
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should briefly document the mechanic of the tests here.


class TestBern(unittest.TestCase):
def test_bern(self):
pari.bernfrac(0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

what this is supposed to test? and why keeping ;?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It test that it doesn't crash. I keep them mainly to stick with the original GP test file.

I keep ; during developement as an help to associate results with the corresponding test.
Keeping them after can has no sense. I will remove them.

class TestBern(unittest.TestCase):
def test_bern(self):
pari.bernfrac(0);
pari.bernfrac(1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

idem

@jdemeyer
Copy link
Collaborator

I think that we should not add all those file to cypari2, especially because we want to support multiple versions of PARI and the version that we add is just one version.

Instead we should just use tests_generator.py (where is that script anyway?) and test directly the output of that.

@videlec
Copy link
Collaborator

videlec commented Jan 17, 2018

I don't think that test_generator.py is actually generating the test files in their current form. This message is very misleading. Though it is important to keep the information from which PARI test it came from.

@vinklein
Copy link
Contributor Author

vinklein commented Jan 17, 2018

The comments # This file was generated by tests_generator.py should be ignored for now (And removed).
test_generator.py exist but it only partly generate the unittest files, most of the work has been done manually.
That's because the original gp doctests are written with a lot of different kind of syntax.

@jdemeyer
Copy link
Collaborator

Sorry for sounding a bit negative, but I don't quite understand why you are using unittests here. I thought that the main point of #4 was to have Python doctests. That is not what you doing here.

Now it seems that you just copy PARI tests to cypari2 which is a bit pointless because it's not the job of cypari2 to test PARI. It should be the job of cypari2 to test the wrapping mechanism, not to test the PARI library itself.

@vinklein
Copy link
Contributor Author

vinklein commented Jan 18, 2018

Sorry for sounding a bit negative, but I don't quite understand why you are using unittests here. I thought that the main point of #4 was to have Python doctests. That is not what you doing here.

An understandable question. If the main goal is to have Python doctest this PR have no sense. But the choice of unittests is more an answer to the question "What is the good way to port GP tests into cypari2".
For the choice unittest vs doctest :

  • unittest is more flexible overall.
  • IMO the main question when chosing between unittest or doctest is to know if your tests are mainly here for informative value (showing what can be done) or if your tests are here to try to test every case.
    GP tests looks more to be of the latter kind, and a lot of tests result are pretty unreadable given their size or structure (like testing many function with many parameters in nested loops) and therefore have a poor value as documentation.

It should be the job of cypari2 to test the wrapping mechanism, not to test the PARI library itself.

Can you expand on that ?
Does test something like pari.addprimes([pari.nextprime(1e9), pari.nextprime(1e10)]) has no added value for you ?

@videlec
Copy link
Collaborator

videlec commented Jan 18, 2018

The GP tests are a natural source of code examples (that is moreover tested). This PR is not testing PARI/GP in any way but rather if GP code can easily be ported in cypari2. It checks for coherences and helps identifying what is the missing in cypari2 vs GP.

Vincent Klein added 2 commits January 18, 2018 11:48
Add file's description.
Remove the option to use test suite.
@jdemeyer
Copy link
Collaborator

IMO the main question when chosing betwwen unittest or doctest is to know if your tests are mainly here for informative value (showing what can be done)

The GP doctests (i.e. the tests appearing in the PARI user documentation) are meant as documentation/examples, analogous to Python doctests.

The PARI unittests (i.e. the tests in the src/pari directory in the PARI sources) are meant as pure tests.

I think it makes most sense to port the GP doctests to cypari2. Porting the PARI unittests seems useless.

@vinklein
Copy link
Contributor Author

vinklein commented Jan 31, 2018

Porting the PARI unittests seems useless.

I really don't see how it can be useless. Unless you have a way to ensure that cypari2 is perfectly iso-functional with pari. Saying it's useless it's the same as saying "the wrapping is perfect and will never fail".
I thinks you mean it's not worth it.

Now what do we do with these unittest ?

@jdemeyer
Copy link
Collaborator

the wrapping is perfect and will never fail

It's not that the wrapping will never fail. It's more like "the wrapping will either work or fail badly". It would be really surprising if the wrapping would work for most functions but not all.

Of course, the cases where we manually wrap some functions should be tested properly.

@vinklein vinklein closed this Apr 6, 2018
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.

3 participants