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

Test that classes are printable and srepr:able #22666

Open
oscargus opened this issue Dec 13, 2021 · 4 comments
Open

Test that classes are printable and srepr:able #22666

oscargus opened this issue Dec 13, 2021 · 4 comments

Comments

@oscargus
Copy link
Contributor

It seems like there should be a test in test_args that all classes are printable (in the sense that str, srepr, latex and pretty does not give an error) and that srepr of the object can be used to recreate the same object. The printable, I know how to implement (although it is currently not the state of the code), but for the second it is not that simple.

Using sympify will not work for all classes it seems. Especially vectors that are recreated as a member of its parent system, e.g. sympify(srepr(C.i)) will complain that the member i is not available. Using eval will require all imports to happen at the top level and not inside the test-functions (as is sometimes the case now). This may be the most feasible approach, but there are some duplicate class names I think.

Any ideas or opinions?

@ThePauliPrinciple
Copy link
Contributor

It might be that some objects are a subclass of Printable but not Basic, in which case sympify/_sympify might not work nicely with them.

I like the idea of having stricter checks for SymPy objects. But perhaps test_args is not the right place? It certainly facilitates the testing you are looking for, but its name suggests a different function (namely testing arguments, not printing).

Perhaps this can be generalized, with one file containing the creation of all these objects and then there can be seperate files that test certain aspects (like the arg invariance, or printing and possibly other formal requirements that are currently not being tested)

@oscarbenjamin
Copy link
Contributor

Maybe test_args can be renamed to test_basic_subclasses. It's the onlt place that forces all subclasses to appear so it's a good place to try and impose consistency.

@smichr
Copy link
Member

smichr commented Dec 15, 2021

Another thing that I would like to see tested is that func_name gives the canonical name (e.g. RootOf) for an object.

@ThePauliPrinciple
Copy link
Contributor

ThePauliPrinciple commented Dec 15, 2021

Another thing that I would like to see tested is that func_name gives the canonical name (e.g. RootOf) for an object.

Out of curiosity, are there any situations where this is "sensitive"?
func_name seems to use obj.func.__name__ if defined and type(obj) otherwise + some formatting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants