Permalink
Browse files

Very early first go at testing using 'behave' library for behaviour-d…

…riven dev
  • Loading branch information...
robintw committed Aug 30, 2015
1 parent 3c7264e commit bdc628988ded5d23d9730eee0401ee2637d5a95b
Showing with 63 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +12 −0 test/example_script2.py
  3. +6 −0 test/features/basic.feature
  4. +20 −0 test/features/steps/basic.py
  5. +22 −0 test/features/steps/behave_utils.py
View
@@ -3,6 +3,9 @@
*.npy
*.swp
*.pdf
*.json
test/.recipyrc
.ipynb_checkpoints/
# Byte-compiled / optimized / DLL files
View
@@ -0,0 +1,12 @@
import sys
import os
sys.path.insert(0, os.path.abspath('../'))
import recipy
import numpy
arr = numpy.arange(10)
arr = arr + 500
# We've made a fairly big change here!
numpy.save('simple_test.npy', arr)
@@ -0,0 +1,6 @@
Feature: Basic recipy use
Scenario: Run a simple test
Given we have recipy set up for testing
When we run some code
Then an entry should be added to the database
@@ -0,0 +1,20 @@
from behave import given, when, then
import os
from behave_utils import setup_testing_environment
@given('we have recipy set up for testing')
def step_impl(context):
context.db_file = setup_testing_environment("/Users/robin/code/recipy/test/scratch/")
@when('we run some code')
def step_impl(context):
print(os.system("python example_script2.py"))
@then('an entry should be added to the database')
def step_impl(context):
with open(context.db_file, 'r') as f:
contents = f.read()
assert "simple_test.npy" in contents
@@ -0,0 +1,22 @@
import os, shutil
TESTING_CONFIG = """[database]
path = %s
"""
def setup_testing_environment(path):
# Remove the dir if it exists already
if os.path.exists(path):
shutil.rmtree(path)
# Make the directory first
os.makedirs(path)
db_file = os.path.join(path, 'DB.json')
config_file_contents = TESTING_CONFIG % db_file
# Write testing configuration file
with open('/Users/robin/code/recipy/test/.recipyrc', 'w') as f:
f.write(config_file_contents)
return db_file

0 comments on commit bdc6289

Please sign in to comment.