Skip to content

Instantly share code, notes, and snippets.

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
nvgoldin / prefer_unittest_mock.md
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
nvgoldin / __del__.py
Last active April 25, 2020 10:44
example of __del__ drawback: order of clearing globals not promised
In [2]: # %load risk_of__del__globals_cleanup.py
...: import gc
...:
...: class GlobalCounter:
...: value = 0
...:
...:
...: class SomeKlass:
...: def __del__(self):
...: print('in SomeKlass __del__')
@nvgoldin
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)
FROM python:2.7.14-alpine
RUN apk add --no-cache \
--allow-untrusted \
--repository \
http://dl-3.alpinelinux.org/alpine/edge/testing \
hdf5 \
hdf5-dev && \
apk add --no-cache \
build-base
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 = """
domains:
@nvgoldin
nvgoldin / transient.py
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
nvgoldin / inspect_local.sh
Created April 23, 2017 08:48
inspect whether a variable declared with 'local' is local
#!/bin/bash -ex
a="global"
b="global"
c="global"
d="global"
function koko() {
local a b c d
a="xxx"
b="zzz"
c="ddd"
@nvgoldin
nvgoldin / local_vars.sh
Created April 18, 2017 07:08
bash local variables and assignment in the same line masking the return code [SC2155]
> cat local.sh
#!/bin/bash -x
function test1() {
echo "test1"
local kk=$(wtf)
echo $?
}
function test2() {
@nvgoldin
nvgoldin / ost_lago_runtest.sh
Created April 2, 2017 08:54
Re-run 'lago ovirt run-test' individual test
./run_suite.sh -o /dev/shm/ost basic-suite-master
# failure/stop
export LAGO_INITFILE_PATH="/home/ngoldin/src/gerrit.ovirt.org/ovirt-system-tests/basic-suite-master/"
export LAGO_WORKDIR_PATH="/dev/shm/ost"
export SUITE="basic-suite-master"
cd /dev/shm/ost
PYTHONPATH=$PYTHONPATH:/home/ngoldin/src/gerrit.ovirt.org/ovirt-system-tests/basic-suite-master/ lago ovirt runtest /home/ngoldin/src/gerrit.ovirt.org/ovirt-system-tests/basic-suite-master/test-scenarios/002_bootstrap.py
@nvgoldin
nvgoldin / sdk4_types.py
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'