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

add debugging support #56

Closed
wants to merge 10 commits into from
Closed

add debugging support #56

wants to merge 10 commits into from

Conversation

metaperl
Copy link
Contributor

@metaperl metaperl commented Mar 4, 2017

No description provided.

@s4w3d0ff
Copy link
Owner

s4w3d0ff commented Mar 6, 2017

After reading through the docs, mock would be appropriate for this repo, especially for unittests. I have no experiance with it, but it seems like exaclty what we want and it is part of the python3 standard library. I'd like to dig deeper and perhaps write a basic unittest using mock before merging these commits and having the repo depend on it.

@s4w3d0ff s4w3d0ff added the enhancement New feature or bug fix label Mar 6, 2017
@kdb424
Copy link
Contributor

kdb424 commented Mar 15, 2017

Try pytest for unit testing. It will simplify things and is considered one of the best in the industry.

@metaperl
Copy link
Contributor Author

metaperl commented Mar 15, 2017 via email

@s4w3d0ff
Copy link
Owner

s4w3d0ff commented Mar 15, 2017

@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 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.

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 mock but if there is an easier way to do it with mock...

@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 of just getting a new number:

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...

@metaperl
Copy link
Contributor Author

metaperl commented Mar 15, 2017 via email

@metaperl
Copy link
Contributor Author

metaperl commented Mar 16, 2017 via email

@s4w3d0ff
Copy link
Owner

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.

@metaperl
Copy link
Contributor Author

metaperl commented Mar 21, 2017 via email

@s4w3d0ff
Copy link
Owner

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 requests because it was removing LOTS of bugs (and does most of the work for you). With smaller 3rd party modules I have found them to change often (much like this repo).

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?

@s4w3d0ff s4w3d0ff mentioned this pull request Mar 31, 2017
@s4w3d0ff s4w3d0ff closed this Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants