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

Useful error message for TimeFromEpoch scale conversion error. #2046

Merged
merged 14 commits into from
Feb 11, 2014

Conversation

kaichogami
Copy link
Contributor

Pull request for the updated error message in case of failure in scale conversion in TimeFromEpoch. First pointed in issue #1829 (now closed).
@taldcroft please review these changes and tell me if any changes are required!
Thank you!


with pytest.raises(ScaleValueError) as exc:
t = Time(Time.now().cxcsec, format='cxcsec', scale='ut1')
assert str(exc) == ScaleValueError
Copy link
Member

Choose a reason for hiding this comment

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

This assert statement needs to be in the outer block, not in the with pytest.raises() as exc: block. The reason is that the t = Time() statement raises the exception and the assert statement never gets executed. If it did, then you would see a failure (see next comment).

Copy link
Member

Choose a reason for hiding this comment

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

str(exc) will be the text of the error message, so the line can be

assert str(exc).startswith("Cannot convert from 'cxcsec' epoch "
                           "scale 'tt' to specified scale 'ut1', got error:")

In this case you don't need to explicitly check the entire rest of the error message.

@kaichogami
Copy link
Contributor Author

@taldcroft I should be apologising for not taking PEP8 into consideration even after reading about it.
I made the changes as you suggested, but please review it again for it might contain mistakes. Sorry for that.
On the side note, I still have very less idea about testing cases in python, and py.test package(I still dont fully understand what I am doing in that test case). Can you please point where I should begin learning about it? Thanks!

@embray
Copy link
Member

embray commented Feb 5, 2014

@kaichogami No problem about PEP8: It has a lot of pedantic little rules that nobody can be expected to learn exactly all at once, and it's not hard to forget or miss something. The reason it's easy to over time is that most Python code in the public (in particular anything written in the last 5 year or so) tries to adhere to it. So at a certain point, once you've stared at enough Python code, it just "looks PEP8" or not without thinking about it.

@kaichogami
Copy link
Contributor Author

I understand. I suppose its like learning a new language. I will get used to it, hopefully.
Also @embray why is it saying Travis Cl failed? What should I do to make it successful?

@embray
Copy link
Member

embray commented Feb 6, 2014

@kaichogami Click the "Details" link: https://travis-ci.org/astropy/astropy/builds/18288472

There are several different "builds". Look for the column called "Env": The SETUP_CMD part indicates what actual test is being performed. The SETUP_CMD='egg_info' ones are generally uninteresting (they just have to do with installation). What you want to look at are the ones that start with SETUP_CMD='test'. Those are the ones that are actually running all of the Astropy tests which are failing on most platforms (the one at the bottom that's gray timed out entirely). Did you run the tests locally?

@kaichogami
Copy link
Contributor Author

@embray Yes the tests earlier were failing. I should have double checked them. On closer inspection I felt that there was no need for the "assert statement". I changed it accordingly.
Its not showing Travis Cl failed again, so I suppose its safe to assume its working fine now. If I am still doing something wrong, please let me know. Thank you!

@@ -1249,7 +1249,7 @@ class TimeFromEpoch(TimeFormat):
def __init__(self, val1, val2, scale, precision,
in_subfmt, out_subfmt, from_jd=False):
self.scale = scale
# Initialize the reference epoch which is a single time defined in subclasses
# Initialize the reference epoch which is a single time defined in subclasses
Copy link
Member

Choose a reason for hiding this comment

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

These whitespace changes should be removed from the patch.

@kaichogami
Copy link
Contributor Author

Sorry for making it review again and again, I will make sure I don't make same mistakes in the next PR. I hope this settles all the PEP8 issues. If there is still something I missed please let me know.
Thanks a lot! I have learnt many new things! :)

@@ -310,6 +310,9 @@ Bug Fixes

- ``astropy.time``

- Fix a problem where scale conversion problem in TimeFromEpoch
was not showing a useful error.
Copy link
Member

Choose a reason for hiding this comment

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

Just one more thing that we should have mentioned earlier. The pull request issue number should be included, so it should be was not showing a useful error. [#2046].

@kaichogami
Copy link
Contributor Author

I have been trying, but for some reason, its not passing the Travis Cl build. I dont really know why is this happening. I just added [#2046] and its not passing the test. I would appreciate help now.
Thanks!

@taldcroft
Copy link
Member

@astrofrog or @eteq - This is giving a Travis fail on Numpy 1.5, but I think it's unrelated to this PR. Can you try re-running the test?

@eteq
Copy link
Member

eteq commented Feb 10, 2014

@taldcroft - restarted, but there's a few builds ahead in the queue so it might be a bit.

@kaichogami
Copy link
Contributor Author

And its working.

taldcroft added a commit that referenced this pull request Feb 11, 2014
Useful error message for TimeFromEpoch scale conversion error.
@taldcroft taldcroft merged commit c5a75f2 into astropy:master Feb 11, 2014
@taldcroft
Copy link
Member

@kaichogami - merged!

@kaichogami
Copy link
Contributor Author

Thank you! My first successful pull request ever! :)

@taldcroft
Copy link
Member

Congratulations and thanks for your contribution!

@kaichogami kaichogami deleted the bug#1829 branch June 17, 2014 06:23
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

4 participants