-
-
Notifications
You must be signed in to change notification settings - Fork 164
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
add debugging support #56
Conversation
After reading through the docs, |
Try pytest for unit testing. It will simplify things and is considered one of the best in the industry. |
My comments here are a bit off-topic. My fork of python-poloniex has gone
way away from the mainline and I dont expect all my changes to be accepted.
One thing I would recommend though is a change in the way the none is
produced. For instance, right now the nonce is assigned a value during
object initialization:
https://github.com/s4w3d0ff/python-poloniex/blob/master/poloniex/__init__.py#L112
then that value is bound into the arguments to be passed to the API:
https://github.com/s4w3d0ff/python-poloniex/blob/master/poloniex/__init__.py#L182
and then the nonce is incremented defensively:
https://github.com/s4w3d0ff/python-poloniex/blob/master/poloniex/__init__.py#L205
I would recommend that instead of nonce being an attribute of the object,
that it be a property of the object as it is in my fork:
https://github.com/metaperl/python-poloniex/blob/master/poloniex/__init__.py#L178
the advantage of this is that anytime it is requested, it automatically
computes a fresh new value. You could get rid of the finally clause and
also reduce the amount of initialization code by doing it this way.
P.S. - Read about why I do not participate in the reference process
<http://j.mp/refpolicy>.
Terrence Brannon
818-359-0893 (cell)
…On Wed, Mar 15, 2017 at 1:11 PM, Kyle Brown ***@***.***> wrote:
Try pytest for unit testing. It will simplify things and is considered one
of the best in the industry.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#56 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABTLeP3NPLK57JwU-TK9t6_AQKAvmH4ks5rmBvBgaJpZM4MTO8h>
.
|
@kdb424
And the main issue I am having with unittests is figuring out a clean way to bypass making real calls to poloniex. Perhaps only make 2 test api calls to poloniex (1 private and 1 public) then the rest of the unittests would just be checking the url that would be sent to polo (without actually sending). This could probably be done without @metaperl The reason I have the nonce as a saved value is so that the nonce builds on itself (instead of calling the from time import time
from timeit import timeit
i = int(time()*1000)
def nonce():
global i
i += 1
return i
def nonce2():
return int(time()*1000)
timeit(nonce)
# 0.13286900520324707
timeit(nonce2)
# 0.3373839855194092 I am sure there is a better way to achieve this... |
On Wed, Mar 15, 2017 at 5:01 PM, s4w3d0ff ***@***.***> wrote:
@kdb424 <https://github.com/kdb424> pytest was going to be my first
choice, but mock seems to be built for things like APIs. Again I know
nothing about mock and how it actually works, but the docs
<https://docs.python.org/3.5/library/unittest.mock.html> claim:
It (mock) allows you to replace parts of your system under test with mock
objects and make assertions about how they have been used.
And the main issue I am having with unittests is figuring out a clean way
to bypass making real calls to poloniex.
Draw a distinction between unit tests and integration tests? The python
BitTrex API has both types of tests:
https://github.com/ericsomdahl/python-bittrex/blob/master/bittrex/test/bittrex_tests.py
Perhaps only make 2 test api calls to poloniex (1 private and one public)
then the rest of the unittests would just be checking the url that would be
sent to polo (without actually sending). This could probably be done
without mock but if there is an easier way to do it with mock.
@metaperl <https://github.com/metaperl> The reason I have the nonce as a
saved value is so that the nonce builds on itself (instead of calling the
time() and int() functions every time), thus making execution of a new
nonce take 1/3 the time it would if getting a new number:
I see. However, I started getting rejections from Poloniex because of
duplicate nonce values. I didnt save the exact error messages. But I
re-implemented that part as a property and havent had the problem since.
… —
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#56 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABTLfqNEY_9aJJHD_rOlTKHIY1icGs1ks5rmFGzgaJpZM4MTO8h>
.
|
P.S. - Read about why I do not participate in the reference process
<http://j.mp/refpolicy>.
Terrence Brannon
818-359-0893 (cell)
On Wed, Mar 15, 2017 at 5:01 PM, s4w3d0ff ***@***.***> wrote:
@kdb424 <https://github.com/kdb424> pytest was going to be my first
choice, but mock seems to be built for things like APIs.
`mock` is often used with a unit-testing framework. So you could use it
with pytest, nose, etc
However, using something like mock to override methods is debatable
practice. Purists, and people from more strict OO backgrounds would say
that properly designed OO software would be using Dependency Injection -
https://github.com/google/pinject
|
I see now how mock works, your right, it is probably better to just distinguish between the two types of tests. I randomly came across this today: http://code.activestate.com/recipes/580745-retry-decorator-in-python/ |
Yes, I am getting exceptions from requests on a regular basis. So some sort
of retry functionality is important. Here is what I put around the __call__
method today:
metaperl@1076678#diff-eeaeffee5a0554a0261f80f7b06417c3R186
I personally like 3rd party modules because they get a lot of usage and a
lot of patches from other people.
Do you like manually pasting in code instead of 3rd party modules?
P.S. - Read about why I do not participate in the reference process
<http://j.mp/refpolicy>.
Terrence Brannon
818-359-0893 (cell)
…On Tue, Mar 21, 2017 at 3:14 PM, s4w3d0ff ***@***.***> wrote:
I see now how mock works, your right, it is probably better to just
distinguish between the two types of tests.
I randomly came across this today: http://code.activestate.com/
recipes/580745-retry-decorator-in-python/
I haven't tested it, but it seems similar to what your latest commit does.
Could probably use it if you don't want to have another 3rd party lib to
depend on. I am considering adding it to v0.3.x as an optional feature if
it is indeed legit.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#56 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABTLXd-1CwvpqmzuaA-LCEtd4I4G1fRks5roCF5gaJpZM4MTO8h>
.
|
I personally would not like to rely on 3rd party modules (I feel better about it if the module is adopted into python3 core libs), and since I have been advertising this repo as 'python2 and 3 compatible', I try to stay away from any unnecessary 3rd party modules that may cause more problems than they fix. If all I need is a simple, single function from a 3rd party module, I would prefer not depending on it directly. If there is a need for more functionality from the module later on, then I consider depending on the entire module. Maybe it is just me... but it has saved me headaches. This repo uses I don't "like" to copy/paste code but if all I need is 20 lines of basic code, why download 20k+ lines of useless code onto your system to import 20 lines into another 3rd party module? |
No description provided.