Unittest
Doctest
class Title | |
def initialize(string) | |
@string = string | |
end | |
def fix | |
small_words = %w(of a and the an) | |
new_title = [] | |
@string.downcase.split.each_with_index do |element, index| |
source 'https://rubygems.org' | |
ruby '2.1.1' | |
gem 'rails', '4.1.0' | |
gem 'sass-rails', '~> 4.0.3' | |
gem 'uglifier', '>= 1.3.0' | |
gem 'coffee-rails', '~> 4.0.0' | |
gem 'jquery-rails' | |
gem 'jquery-ui-rails' | |
gem 'turbolinks' |
describe BetterCsv do | |
it 'has a nice API' do | |
parser = BetterCsv.parse('info.csv', headers: :first_row) | |
parser.each_row do |parse_result| | |
next if parse_result.error? | |
puts "Found the name and phone #: #{parse_result.name}, #{parse_result.telephone}" | |
end | |
end | |
end |
import pytest | |
def product_index(request): | |
limit = request.GET.get('limit') | |
offset = request.GET.get('offset') | |
if limit and limit.isdigit(): | |
limit = int(limit) | |
else: | |
limit = 10 |
import pytest | |
def product_index(request): | |
limit = parse_parameter(request, 'limit', int, default=10) | |
offset = parse_parameter(request, 'offset', int, default=0) | |
return limit, offset | |
def parse_parameter(request, name, klass, default=None): | |
try: | |
return klass(request.GET.get(name, default)) |
pluto:~ $ ipython | |
Python 2.7.8 (default, Aug 24 2014, 21:26:19) | |
Type "copyright", "credits" or "license" for more information. | |
IPython 2.2.0 -- An enhanced Interactive Python. | |
? -> Introduction and overview of IPython's features. | |
%quickref -> Quick reference. | |
help -> Python's own help system. | |
object? -> Details about 'object', use 'object??' for extra details. |
require 'test_helper' | |
describe 'csv' do | |
describe 'encoder' do | |
it 'should properly enclose quotes and commas' do | |
# From http://www.yelp.com/healthscores | |
# | |
# Field values that contain quotation marks or commas must be enclosed | |
# within quotation marks. In addition, each quotation mark in the field | |
# value must be preceded with a quotation mark. This is consistent with |
#!/usr/bin/env python | |
from setuptools import setup, find_packages | |
import sys | |
if sys.argv[1] == 'test': | |
import multiprocessing, logging | |
from billiard import util | |
with open('requirements.txt') as f: | |
required = f.read().splitlines() |
Unittest
Doctest
pluto:~ $ mkdir project | |
pluto:~ $ cd !$ | |
cd project | |
pluto:~/project $ pyvenv venv | |
pluto:~/project $ ls | |
venv/ | |
pluto:~/project $ source venv/bin/activate | |
pluto:~/project $ which python | |
/Users/me/project/venv/bin/python | |
pluto:~/project $ python --version |