Skip to content

Instantly share code, notes, and snippets.

View dockerfile-for-oren
FROM python:3.9-slim-buster
WORKDIR /tor-scraper
RUN mkdir /tor-scraper/nltk_data
ENV NLTK_DATA=/tor-scraper/nltk_data
COPY nltk_data/ /tor-scraper/nltk_data/
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
#CMD [ "python3", "-c", 'nltk.corpus.stopwords.words(\"english\")' ]
nvgoldin /
Created April 20, 2020 06:57
Why you should prefer to use `spec` in unittest.mock

So back to spec and why its important: Basically when you create a MagicMock, you have an object which is not bounded to any interface. This makes testing easy, but on the other hand, your code does use interfaces and they do change over time.

Here is a quick example:

Lets say I'm using a class called HashAPI which provides hashing services and exposes the following interface:

class HashAPI:
    def create_hash(self, key):
        return hash(key)
nvgoldin /
Last active April 25, 2020 10:44
example of __del__ drawback: order of clearing globals not promised
In [2]: # %load
...: import gc
...: class GlobalCounter:
...: value = 0
...: class SomeKlass:
...: def __del__(self):
...: print('in SomeKlass __del__')
nvgoldin / Dockerfile-python:2.7.14-alpine-h5py
Last active January 3, 2021 15:31
Installing tables, h5py in Alpine Docker(python:2.7.14-alpine)
View Dockerfile-python:2.7.14-alpine-h5py
FROM python:2.7.14-alpine
RUN apk add --no-cache \
--allow-untrusted \
--repository \ \
hdf5 \
hdf5-dev && \
apk add --no-cache \
RUN pip install --no-cache-dir --no-binary :all: tables h5py
import pytest
import textwrap
import tempfile
from lago import sdk
def generate_config():
conf = """
nvgoldin /
Created April 23, 2017 16:09
Running 'transient' systemd unit files with dbus
from __future__ import print_function
import uuid
import functools
import hashlib
# TO-DO: switch to pydbus, currently same code
# with pydbus gives errors.
from dbus import SessionBus, SystemBus, Interface
def rand_name():
nvgoldin /
Created April 23, 2017 08:48
inspect whether a variable declared with 'local' is local
#!/bin/bash -ex
function koko() {
local a b c d
nvgoldin /
Created April 18, 2017 07:08
bash local variables and assignment in the same line masking the return code [SC2155]
> cat
#!/bin/bash -x
function test1() {
echo "test1"
local kk=$(wtf)
echo $?
function test2() {
nvgoldin /
Created April 2, 2017 08:54
Re-run 'lago ovirt run-test' individual test
./ -o /dev/shm/ost basic-suite-master
# failure/stop
export LAGO_INITFILE_PATH="/home/ngoldin/src/"
export LAGO_WORKDIR_PATH="/dev/shm/ost"
export SUITE="basic-suite-master"
cd /dev/shm/ost
PYTHONPATH=$PYTHONPATH:/home/ngoldin/src/ lago ovirt runtest /home/ngoldin/src/
nvgoldin /
Last active March 20, 2017 17:42
sdk4 types init
In [1]: import ovirtsdk4 as sdk4
In [2]: sdk4.types
AttributeError Traceback (most recent call last)
<ipython-input-2-3ecb0c730dda> in <module>()
----> 1 sdk4.types
AttributeError: 'module' object has no attribute 'types'