Skip to content

Instantly share code, notes, and snippets.

View Sharadh's full-sized avatar

Sharadh Krishnamurthy Sharadh

View GitHub Profile
@Sharadh
Sharadh / shareAuto.go
Last active July 19, 2020 23:14
Share Auto Simulation that leverages some go concurrency patterns for better batching
package main
import (
"fmt"
"math/rand"
"time"
)
const (
simulationDurationSeconds = 10
@Sharadh
Sharadh / test_yield_fixture_ordering.py
Last active July 16, 2020 04:14
Code snippet to accompany blogpost on 5 pytest best practices
import pytest
@pytest.fixture
def first():
print("Set up first fixture")
yield
print("Clean up first fixture")
@pytest.fixture
@Sharadh
Sharadh / test_tmpdir.py
Created July 13, 2020 03:22
Code snippet to accompany blogpost on 5 pytest best practices
import pytest
def process_file(fp):
"""Toy function that returns an array of line lengths."""
return [len(l.strip()) for l in fp.readlines()]
@pytest.mark.parametrize("filename, expected", [
("first.txt", [3, 3, 3]),
@Sharadh
Sharadh / test_parametrize.py
Created July 13, 2020 03:20
Code snippet to accompany blogpost on 5 pytest best practices
import pytest
def divide(a, b):
return a / b
@pytest.mark.parametrize("a, b, expected, is_error", [
(1, 1, 1, False),
(42, 1, 42, False),
@Sharadh
Sharadh / test_fixture_mutation.py
Created July 13, 2020 03:19
Code snippet to accompany blogpost on 5 pytest best practices
from copy import deepcopy
import pytest
@pytest.fixture
def alex():
return {
"name": "Alex",
"team": "Green",
@Sharadh
Sharadh / mocker_vs_mock.py
Last active June 16, 2021 16:09
Code snippet to accompany blogpost on 5 pytest best practices
"""Add this to <project-root>/mocker_over_mock.py"""
import pytest
try:
import mock # fails on Python 3
except ImportError:
from unittest import mock
@Sharadh
Sharadh / mocker_vs_mock.py
Created July 13, 2020 03:12
Code snippets to accompany blogpost on 5 pytest best practices
"""Add this to <project-root>/mocker_over_mock.py"""
import pytest
try:
import mock # fails on Python 3
except ImportError:
from unittest import mock
@Sharadh
Sharadh / local-development.txt
Last active September 30, 2019 17:08
Amazon Sagemaker + Nerdwallet ML Platform - Blog Post
> nwml train
Starting local training for nwpy-ml-iris
Loading the ml.train entry point...
* Success!
...
Done!
> nwml batch-predict
...
Done!