Skip to content

Instantly share code, notes, and snippets.

View marknagelberg's full-sized avatar

Mark Nagelberg marknagelberg

View GitHub Profile
@marknagelberg
marknagelberg / load_images.py
Created December 1, 2018 23:59
Script part of blog post to load images into a Word Document
from docxtpl import DocxTemplate, InlineImage
import sys
import os
word_doc_template = sys.argv[1]
word_doc_w_images_loaded = sys.argv[2]
image_dirname = sys.argv[3]
# Don't want to overwrite your template with the loaded images version.
assert word_doc_template != word_doc_w_images_loaded
@marknagelberg
marknagelberg / load_word_doc_post_num_posts_by_author_plot.py
Last active December 1, 2018 23:56
load_word_doc_post_num_posts_by_author_plot.py
data = pd.read_csv('results.csv')
num_posts_by_author = data.groupby('author').size().sort_values(ascending = True)
num_posts_by_author_plot = num_posts_by_author.plot('barh', figsize=(5,5))
num_posts_by_author_plot.set_xlabel('Number of Posts on Marginal Revolution')
fig = num_posts_by_author_plot.get_figure()
fig.savefig('report_images/num_posts_by_author_plot.png', bbox_inches="tight")
@marknagelberg
marknagelberg / app_deploy_tests.py
Created October 14, 2018 00:29
Tests for app deploy
from .conftest import new_name, test_client, create_database
def test_new_name(new_name):
assert new_name.name == 'Mark'
def test_test_client(test_client):
assert test_client is not None
@marknagelberg
marknagelberg / index_new.html
Created October 14, 2018 00:27
Updated index.html to print loaded data from database
<h1>Hello World!</h1>
<br>
<h3>Please enter a name:</h3>
<form method=post>
{{ form.csrf_token }}
{{ form.name.label }}
{{ form.name}}
@marknagelberg
marknagelberg / app_revised_for_system_tests.py
Created October 14, 2018 00:26
app.py revised to be more interesting for system tests
from flask import Flask, render_template, Blueprint
from .forms import NameForm
from .models import Name
from . import db
bp = Blueprint('app', __name__)
@bp.route('/', methods=['GET', 'POST'])
def home():
form = NameForm()
@marknagelberg
marknagelberg / app_deploy_db_fixture.py
Created October 14, 2018 00:21
App deploy testing code to create database fixture
import pytest
from app.models import Name
from app import db
@pytest.yield_fixture(scope='module')
def create_database():
db.create_all()
name = Name(name='Mark')
db.session.add(name)
@marknagelberg
marknagelberg / app_deploy_db_fixture.py
Created October 14, 2018 00:21
App deploy testing code to create database fixture
import pytest
from app.models import Name
from app import db
@pytest.yield_fixture(scope='module')
def create_database():
db.create_all()
name = Name(name='Mark')
db.session.add(name)
@marknagelberg
marknagelberg / app_deploy_app_fixture.py
Created October 14, 2018 00:19
App Deploy Application instance testing_client fixture
import pytest
from app import create_app
@pytest.yield_fixture(scope='module')
def test_client():
app = create_app('testing')
testing_client = app.test_client()
ctx = app.app_context()
ctx.push()
@marknagelberg
marknagelberg / app_deploy_test_fixture_2.py
Created October 13, 2018 23:40
App Deploy blog post on testing - using fixture
from .conftest import new_name
def test_new_name(new_name):
assert new_name.name == 'Mark'
@marknagelberg
marknagelberg / app_deploy_name_fixture.py
Created October 13, 2018 23:36
Name fixture in app deploy blog post on testing
import pytest
from app.models import Name
@pytest.fixture(scope='module')
def new_name():
name = Name(name='Mark')
return name