This document is a reference for common testing patterns in a Django/Python project using Pytest.
Contents:
#!/usr/bin/env bash | |
# | |
# A Bash script to run a TDD loop for building a Python module to pass tests. | |
set -euo pipefail | |
# How many times to loop. | |
ATTEMPTS=4 | |
# The system prompt to use when creating the initial version. |
#!/usr/bin/env bash | |
# | |
# Get the value of a tag for a running EC2 instance. | |
# | |
# This can be useful within bootstrapping scripts ("user-data"). | |
# | |
# Note the EC3 instance needs to have an IAM role that lets it read tags. The policy | |
# JSON for this looks like: | |
# | |
# { |
#!/usr/bin/env bash | |
# | |
# Try and squash unstaged changes into existing branch commits. | |
# | |
# This command examines each unstaged file and attempts to create a fix-up | |
# commit to squash it into its natural parent in the current branch. | |
# | |
# - If it's able to do this for all modified files, the fix-up files are | |
# automatically squashed in. | |
# |
# Python start-up file | |
# -------------------- | |
# Ensure a PYTHONSTARTUP environment variable points to the location of this file. | |
# See https://docs.python.org/3/using/cmdline.html#envvar-PYTHONSTARTUP | |
# Always have pp available | |
from pprint import pprint as pp | |
# Pre-emptively import datetime as I use it a lot. | |
import datetime |
#!/usr/bin/env python | |
""" | |
Print a breakdown of the passed filepaths by CODEOWNER team. | |
This script requires the `codeowners` CLI tool to be installed and available on the $PATH. | |
https://github.com/hmarr/codeowners | |
Intended usage is to pipe filepaths into this script from the root of a repo: | |
cat filepaths.txt | codeowner-breakdown |
import os | |
import time | |
import nox | |
@nox.session(python=["3.10", "3.11", "3.12"]) | |
@nox.parametrize("django_constraint", ["<4.2", "<4.3", "<5.1"]) | |
def tests(session: nox.Session, django_constraint: str) -> None: | |
""" |
#!/usr/bin/env bash | |
# | |
# Bootstrap script for setting up a new OSX machine | |
# | |
# This should be idempotent so it can be run multiple times. | |
# | |
# Some apps don't have a cask and so still need to be installed by hand. These | |
# include: | |
# | |
# - Twitter (app store) |
from celery import chain | |
from django.core.management.base import BaseCommand | |
from . import tasks | |
class Command(BaseCommand): | |
def handle(self, *args, **kwargs): |
#!/bin/bash | |
DEVICE=/dev/$(lsblk -n | awk '$NF != "/" {print $1}') | |
FS_TYPE=$(file -s $DEVICE | awk '{print $2}') | |
MOUNT_POINT=/data | |
# If no FS, then this output contains "data" | |
if [ "$FS_TYPE" = "data" ] | |
then | |
echo "Creating file system on $DEVICE" |
This document is a reference for common testing patterns in a Django/Python project using Pytest.
Contents: