|
I'm not sure if my post was incoherent or what but I'm not sure how you can suggest mocking is a code smell? If you're having to create dozens of mocks then sure, but that's a very clear indication that your unit under test is doing to much and has nothing to do with the mocks themselves. Similarly, and I'll use a web API as an example (which is convenient because in the above mentioned book after glancing that's what he's using under his mock section), how can you unit test that a barbones function making a POST is making the POST? You either actually connect to the real service or you actually connect to a test service that tournament some test data, both of which would result in a horrible unit test. The only good option you have is to use a mock that doesn't actually create a network connection and just immediately returns some known value that you assert against. Anything else and you don't actually know what you're testing. That's the canonical example but the same principle applies between between basic function calls between two objects. If you're testing method A, and method B is called at some point in method A, you don't actually care what method B is doing and unless you mock method B out to return a known value (at the time of the test) you don't even know what you're testing. I'm definitely not new to unit testing practices or TDD, which is what I was trying to convey in a hamfisted way by name dropping popular and modern frameworks for other languages. I'll continue to read that book though and from some searching it looks like flexmock is maybe more what I'm looking for than the built in. Edit: and to be extra clear I was seeing a lot of people using the @patch decorator which I didn't like, as a lot of examples just had like 5+ decorators sitting on their test method and it just seemed like a mess. Mr. Crow fucked around with this message at 20:01 on Oct 26, 2017 |
# ? Oct 26, 2017 19:57 |
|
|
# ? May 15, 2024 04:13 |
|
Mr. Crow posted:I'm not sure if my post was incoherent or what but I'm not sure how you can suggest mocking is a code smell Your post itself seemed to be saying mocks were a code smell. Your other points are exactly good times to be using mocks. edit: oh, you were objecting to using the patch decorator. You don't have to use it as a decorator. You can use it as a function/context-manager as well. It's just a tool. You use it as makes sense. Thermopyle fucked around with this message at 20:25 on Oct 26, 2017 |
# ? Oct 26, 2017 20:01 |
|
The point of patching with mock is to avoid unwanted side-effects the unit under test produces. Patching is definitely not a smell in a unit test on its own. There's many cases where there's no viable alternative. Sometimes you patch things that don't produce side-effects, but you just don't want to worry about in the context of your unit test. Yeah, if you see a ton of patches/patch decorators maybe that's a smell, but not necessarily with the test. More likely the unit is doing too much.
|
# ? Oct 26, 2017 20:21 |
|
John Big Booty posted:
This worked. Thank you!
|
# ? Oct 26, 2017 21:04 |
|
Scipy 1.0.0 is out. Check out the highlights listed on that page. Two standouts for me: 1: Windows wheel. This means the whole Scipy stack is installable via Pip on Windows. 2: Long-overdue ode improvement. Previously, there were two APIs: odeint, which was easy-to-use, but limited, and ode, which was powerful, but convoluted. The new api: solve_ivp, provides robust options with an odeint-like API (yet even cleaner) Dominoes fucked around with this message at 21:39 on Oct 26, 2017 |
# ? Oct 26, 2017 21:31 |
|
Kind of surprised they didn't have a wheel out already. I haven't had to worry about pip installing stuff on Windows in a long time because so much stuff already has a wheel.
|
# ? Oct 26, 2017 21:43 |
|
Thermopyle posted:Kind of surprised they didn't have a wheel out already. Scipy was a glaring exception until now; it had to do with Fortran compilers/licenses. Read here for details.
|
# ? Oct 26, 2017 22:03 |
|
Does anyone have any good examples/blogs/libraries using functional programming in Python?
|
# ? Oct 27, 2017 01:36 |
|
Hughmoris posted:Does anyone have any good examples/blogs/libraries using functional programming in Python? https://www.dontdoit.com
|
# ? Oct 27, 2017 01:39 |
|
Check out Toolz.
|
# ? Oct 27, 2017 09:10 |
|
What’s a good python podcast for beginners?
|
# ? Oct 27, 2017 13:23 |
|
Dominoes posted:Check out Toolz. Better suggestion: don’t.
|
# ? Oct 27, 2017 14:48 |
|
Functional programming in python can be done effectively and sometimes it can be done appropriately, but generally you shouldn't go "ok I'm going to write this program functionally". Use it when it makes sense. Guido doesn't optimize style for writing functionally and it shows. https://stackoverflow.com/questions/1017621/why-isnt-python-very-good-for-functional-programming That list isn't exactly right, but it gets the idea across.
|
# ? Oct 27, 2017 15:10 |
|
Thermopyle posted:Functional programming in python can be done effectively and sometimes it can be done appropriately, but generally you shouldn't go "ok I'm going to write this program functionally". its more of a backwards thing: guido is stuck in the late 80s-90s when it comes to programming ergonomics and thus will never see any benefit in functional programming and the sycophants who make up cPython will thus never do it The upshot is that functional programming in python is far more painful than it needs to be and so you shouldn't use it, making it more painful since no developer will optimize for it, and...
|
# ? Oct 27, 2017 15:24 |
|
Dominoes posted:Check out Toolz. Thermopyle posted:Functional programming in python can be done effectively and sometimes it can be done appropriately, but generally you shouldn't go "ok I'm going to write this program functionally". Thanks for the links.
|
# ? Oct 27, 2017 15:42 |
|
Matthew Rocklin has some great talks demonstrating the use of toolz. Check vimeo and YouTube.
|
# ? Oct 27, 2017 16:14 |
|
There's also http://coconut-lang.org
|
# ? Oct 27, 2017 18:38 |
|
LochNessMonster posted:What’s a good python podcast for beginners? I'm very much a beginner and I enjoy Talk Python to Me and Python Bytes. podcast.init is a little more in-depth but still worth a shot.
|
# ? Oct 28, 2017 21:13 |
|
This may be better suited to stack overflow but: I'm trying to implement memoizing for class methods, but implementing a cache for each class instance, not each method. I also want the cache to be based a number of instance variables which aren't necessarily called as function arguments. I have a model which has lots of methods which include calls to earlier methods, so caching fails if a state variable has changed but it isn't a method argument. Basically I would like a combination of these two bits of code: https://stackoverflow.com/questions/33859731/how-to-memoize-method-when-one-of-its-memoized-parameters-should-be-an-instance and this http://code.activestate.com/recipes/577452-a-memoize-decorator-for-instance-methods/ Is this a relatively simple thing to plumb together or much more complex?
|
# ? Oct 28, 2017 21:20 |
|
Slimchandi posted:I'm very much a beginner and I enjoy Talk Python to Me and Python Bytes. podcast.init is a little more in-depth but still worth a shot. thanks, I'll give those a shot!
|
# ? Oct 29, 2017 10:54 |
|
Slimchandi posted:I'm very much a beginner and I enjoy Talk Python to Me and Python Bytes. podcast.init is a little more in-depth but still worth a shot. Wait are programming podcasts really a thing?
|
# ? Oct 31, 2017 18:27 |
|
Yes and there are a lot of them. Some of them are actually good.
|
# ? Oct 31, 2017 18:57 |
|
Rocko Bonaparte posted:Wait are programming podcasts really a thing?
|
# ? Oct 31, 2017 20:45 |
|
Rocko Bonaparte posted:Wait are programming podcasts really a thing? There are literally podcasts for like every single subject, most of them follow the same “two guys talking” format. Those two python podcasts in particular talk about/introduce python packages, interviews the developers of them, etc. It’s not really about programming per say, more about the ecosystem. They were ok for a while but got really stale and boring cause I just didn’t care about any of the packages they were talking about.
|
# ? Nov 1, 2017 18:42 |
|
I find listening to podcasts is a great way for me to internalize things in loads of subjects so a Python podcast aimed at newbies would be amazing for me.
|
# ? Nov 3, 2017 13:05 |
|
Hey dudes: How do you actively test/work on functions in your code? This is a broad-question; I hope this context helps: My workflow has involved editing files in PyCharm or another editor, and having a separate Ipyhon window open with %autoreload 2 set; I import the module. To test, I save the code in the editor, and work in Ipython. I've recently tried Rstudio and Spyder... Love how you can just work entirely in the IDE and run bits of/all your code etc whenever you want. This doesn't appear possible in Pycharm: The run button at the top just runs the whole thing, as if it were a standalone script. The built-in console doesn't use the Spyder/Rstudio behavior I described, and doesn't work with autoreload. Is there any way to do this in Pycharm? Dominoes fucked around with this message at 13:25 on Nov 4, 2017 |
# ? Nov 4, 2017 12:31 |
|
You can use the debugger to stop at a point in the code, hit the console button and interact with the ipython window there (there is also a variables viewer too). Or you can highlight whatever code you want to run, and then right click and choose “execute in python console” and it will run it in an open console (if you have one) or open a new one and execute it there. I used to do exactly what you describe with pycharm + a terminal window but I do it all in pycharm now. I know this is short but I’m phone posting but can provide more detail later if needed.
|
# ? Nov 4, 2017 13:04 |
|
Been a while since I've had to do this but I need to make a GUI for a Python project. Need it to work on Python 3, absolutely needs to work on Windows (better if cross platform, but not required), absolutely need to be able to put it in the system tray, and would prefer it not make me want to die while working with it. Any advice or am I stuck choosing between tkinter and qt or whatever?
|
# ? Nov 4, 2017 16:03 |
|
The March Hare posted:Been a while since I've had to do this but I need to make a GUI for a Python project. Need it to work on Python 3, absolutely needs to work on Windows (better if cross platform, but not required), absolutely need to be able to put it in the system tray, and would prefer it not make me want to die while working with it. Nowadays I use HTML/CSS/JS + Electron when I'm making a Python GUI. Other than that look at PySide, Pyforms, and Kivy to see if any meet your needs.
|
# ? Nov 4, 2017 17:32 |
|
Thermopyle posted:Nowadays I use HTML/CSS/JS + Electron when I'm making a Python GUI. I'm down with Electron in theory but the word on the street is that even the simplest of apps incur a massive overhead. Is this actually true or have things changed a bit? I'm writing a pretty simple app, I don't want it to have a 500MB memory allocation or whatever.
|
# ? Nov 4, 2017 18:37 |
|
The March Hare posted:I'm down with Electron in theory but the word on the street is that even the simplest of apps incur a massive overhead. Is this actually true or have things changed a bit? I'm writing a pretty simple app, I don't want it to have a 500MB memory allocation or whatever. Personally, I don't really care how much memory my application uses. The only thing that matters is if it causes actual problems. For what its worth, a minimal Electron app will use 50-60MB. It's a tradeoff I'm often willing to make to be able to use the best UI design and creation paradigm. If your app is simple I'd probably go with Pyforms (not sure if it does system tray) or PySide. Thermopyle fucked around with this message at 19:02 on Nov 4, 2017 |
# ? Nov 4, 2017 19:00 |
|
The March Hare posted:Been a while since I've had to do this but I need to make a GUI for a Python project. Need it to work on Python 3, absolutely needs to work on Windows (better if cross platform, but not required), absolutely need to be able to put it in the system tray, and would prefer it not make me want to die while working with it. Qt is pretty easy to use
|
# ? Nov 4, 2017 23:20 |
|
QuarkJets posted:Qt is pretty easy to use I used qt a while back and I don't remember it being difficult, but I do remember the documentation for pyqt sort of sucking. I checked out the kivy docs this afternoon and it looks totally fine, probably just going to use it and see what happens. Thanks y'all~
|
# ? Nov 5, 2017 00:08 |
|
Thermopyle posted:Personally, I don't really care how much memory my application uses. The only thing that matters is if it causes actual problems. It's not just the RAM used though, that's all used up by doing random poo poo, with all the performance slowdown that's implied in actually filling those megabytes, especially on a lower specced machine than a developer workstation.
|
# ? Nov 5, 2017 00:27 |
|
Yes, that's what I would call "actual problems".
|
# ? Nov 5, 2017 04:23 |
|
Another gui option is to do the html/css/js route and use the webbrowser standard library module to open your interface in the user's browser. You'd have to use another gui framework to make your system tray icon. Only you can decide if that's something reasonable for your use case.
|
# ? Nov 5, 2017 04:37 |
|
The March Hare posted:I used qt a while back and I don't remember it being difficult, but I do remember the documentation for pyqt sort of sucking. I checked out the kivy docs this afternoon and it looks totally fine, probably just going to use it and see what happens. Thanks y'all~ The documentation for Qt is extensive, and pyqt is basically just a wrapper for that. Anytime that you have a question about pyqt there's a very good chance that your question is actually about qt
|
# ? Nov 5, 2017 07:44 |
|
QuarkJets posted:The documentation for Qt is extensive, and pyqt is basically just a wrapper for that. Anytime that you have a question about pyqt there's a very good chance that your question is actually about qt I've mentioned this previously in the thread, but it's worth repeating here I think: if you want help with PyQt, it is useful to consult the PySide docs instead. The two packages have minor differences, but the PySide docs all give Python examples whereas the PyQt docs are almost non-existent and you frequently get redirected to C++ docs instead.
|
# ? Nov 5, 2017 09:17 |
|
I'd like to package a little tool I made for an outdated OSX. There are a few directories with icons, config files etc Assuming all the imports can be resolved on the target system, Is there a clean packaging technique to distribute a single file instead of a zip that must be decompressed ? I'm on linux. vvv thanks ! unpacked robinhood fucked around with this message at 21:51 on Nov 14, 2017 |
# ? Nov 14, 2017 11:16 |
|
|
# ? May 15, 2024 04:13 |
|
unpacked robinhood posted:I'd like to package a little tool I made for an outdated OSX. There are a few directories with icons, config files etc https://py2app.readthedocs.io/en/latest/ It'll create a .app bundle, which you will still need to zip up because in reality it's just a specially named/structured folder, but that's the standard way to distribute applications on Mac OS.
|
# ? Nov 14, 2017 16:18 |