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
BF: Fix get_text_rendering when Citation is passed with Doi #46
Conversation
citation_bibtex = Citation(_sample_bibtex, path='mypath') | ||
citation_doi = Citation(_sample_doi, path='mypath') | ||
# smoke test | ||
assert_true(get_text_rendering(citation_bibtex)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why just a smoke test ? ideally mock out format_bibtex a nd verify that it gets called in both cases. and you could even verify that they get correct input to them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok -- we should talk about patches. I tried but can't seem to make it work. It does nothing.
@patch('duecredit.io.format_bibtex')
def test_get_text_rendering(mocked_format_bibtex):
citation_bibtex = Citation(_sample_bibtex, path='mypath')
citation_doi = Citation(_sample_doi, path='mypath')
# smoke test
assert_true(get_text_rendering(citation_bibtex))
mocked_format_bibtex.assert_called_with(citation_bibtex.entry)
assert_true(get_text_rendering(citation_doi))
this won't work (assertion fails because mocked_format_bibtex
wasn't called). hints?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Sat, 15 Aug 2015, Matteo Visconti di Oleggio Castello wrote:
this won't work. hints?
because there is a bug! ;) aren't tests great? ;) although bug is only in the
test itself.
I first thought that it is due to some intricacies of mock, so you might
like to read
http://alexmarandon.com/articles/python_mock_gotchas/
http://www.voidspace.org.uk/python/mock/patch.html#where-to-patch
but then, after I added
import pdb; pdb.set_trace()
right before
assert_true(get_text_rendering(citation_bibtex))
it pointed that citation.entry is not BibTeX, it is a str! So we have a bit
"ambigous" API here for the Citation -- entry could be a string key or an
actual DueCreditEntry. Would be nice to add some safeguard I guess, e.g. throw
a warning if provided entry is a string and has new lines in it (unlikely we
should allow keys to have new lines). Or may be we should make it more
explicit??? (make it have two separate parameters -- entry and key)
anyways -- fix here would be
citation_bibtex = Citation(BibTeX(_sample_bibtex), path='mypath')
and then failure would be different and more meaningful ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, the things one learns! how sneaky this was...thanks :-)
also update _sample_doi with a real one
path=citation.path, | ||
version=citation.version, | ||
cite_module=citation.cite_module, | ||
tags=citation.tags) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
future todo -- I don't like that this 'cloning' happens outside of the Citation code. We should may be make entry
a property with a setter, and then just copy old citation (copy.copy) into a new one and override entry
with bibtex one
I keep coming to this PR always thinking we have already merged it ;) please resolve conflicts (and may be address my comment) and let's get it merged |
* origin/master: BF: print description, not just path. Closes duecredit#49 ENH/NF: all conditions must be met ('and' logic) + allow access values from attributes of the arguments RF: improve test, conditioning of the method ENH: few more injections for sklearn BF: catch also AttributeError while getting to the object ENH: few more injections for sklearn DOC: provide custom short long_description adjusting for -m python RF: move external versions into its separate submodule Conflicts: duecredit/tests/test_collector.py Accept remote
Done (but why travis is not running?) |
not sure about travis -- could you push 1 more change to this PR to see if it still doesn't react? |
OK travis got back on track |
BF: Fix get_text_rendering when Citation is passed with Doi
and a new release was tagged ;-) |
We're getting there... however there is still a problem with the injector because there should be two citations for spectral clustering (see below), but only one appears...probably due to how they're stored. Will look into that.