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

Portable python tests #381

Merged
merged 5 commits into from
Nov 10, 2016
Merged

Conversation

bryanwweber
Copy link
Member

@bryanwweber bryanwweber commented Nov 9, 2016

This is a rewrite of #376. The implementation is very similar, relying on a temp directory to store working files, instead of a user directory. I thought about using in-memory only files, but ck2cti expects a string instead of a file handle, so that wouldn't work.

I preferred to implement the working directories as attributes of the CanteraTest class, instead of a module-level method in utilities. This required using super().setUpClass() in a few places where setUpClass was used in a derived class. This requirement is somewhat unfortunate, and could be alleviated by moving the derived setUpClass methods' into a setUp method, but this would cause the setUp method to be run for each test, typically creating a new Solution for each test. This could be slow, although the mechanisms we're using tend to be small, so the time hit shouldn't matter very much. Feedback is appreciated on this point.

@bryanwweber
Copy link
Member Author

The advantage of having the working directory in particular as a class attribute is that it can be removed in the class teardown

@bryanwweber
Copy link
Member Author

bryanwweber commented Nov 9, 2016

The build failures are due to Python 2 vs 3 differences. I'll have to fix it tomorrow; I think the best solution will be to move the extra setUpClass methods into setUp methods. I'll check the timing and make sure it's not a big difference.

@bryanwweber
Copy link
Member Author

Well, creating a new Solution for each test in a setUp method adds about 6 seconds out of 2 minutes to the test runtime on my machine, so that doesn't seem very scalable. So, rather than using super, now this explicitly calls the base class setUpClass method. It seems reasonable to expect that if you want the attributes defined in the base class, you'll have to call the setup function from the base class if you override its setup function. In addition, I made the tearDownClass function pass if the temp directory doesn't exist. Hopefully this will pass the tests.

@@ -33,7 +33,7 @@ def test_mixtureAveraged(self):
self.assertArrayNear(Dbin1, Dbin1.T)

def test_multiComponent(self):
with self.assertRaises(Exception):
with self.assertRaises(AttributeError):
Copy link
Member

Choose a reason for hiding this comment

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

Actually, I think the test here is wrong. The thing that we meant to test there is that multi_diff_coeffs raises an error from Cantera if we are not using a multicomponent model, but of course the typo in the property name also raises Exception, so this is a good example of why it was good to add the CanteraError Python class.

@speth
Copy link
Member

speth commented Nov 9, 2016

To make debugging failing tests easier, it would be nice if there were a way to use test/work as the working directory if the test suite is being run from the Cantera source tree (or more or less equivalently, being run by the runCythonTests.py script)

@bryanwweber
Copy link
Member Author

So the best idea I could come up with to check whether this is an in-source test was to look for SConstruct in the root directory. It works for me locally, let's see if it works on Travis. Hopefully this will also work in other places. I didn't test whether temporary directories get removed properly. Hopefully since they're temp directories, the OS will handle it eventually, if any are left over.

@speth speth merged commit 4e1c45c into Cantera:master Nov 10, 2016
@bryanwweber bryanwweber deleted the portable_python_tests branch November 11, 2016 22:46
@speth speth mentioned this pull request Nov 29, 2016
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.

2 participants