Run tests with guard

Conflicts:
	bin/asciiio
This commit is contained in:
Marcin Kulik
2013-07-25 22:08:03 +02:00
committed by Marcin Kulik
parent 1b0d87c8df
commit 09909137cc
4 changed files with 83 additions and 17 deletions

16
Guardfile Normal file
View File

@@ -0,0 +1,16 @@
# Add files and commands to this file, like the example:
# watch(%r{file/path}) { `command(s)` }
#
guard 'shell' do
watch(%r{src/.+}) { |m| `make` }
watch('Makefile') { |m| `make` }
watch(%r{tests/.+}) { |m| `nosetests #{m[0]}` }
watch(%r{src/(.+).py}) do |m|
test_filename = "tests/#{m[1]}_test.py"
if File.exists?(test_filename)
`nosetests #{test_filename}`
end
end
end

View File

@@ -4,18 +4,18 @@ import uuid
class Config:
def __init__(self):
self.base_dir_path = os.path.expanduser("~/.ascii.io")
self.config_filename = '%s/config' % self.base_dir_path
def __init__(self, base_path="~/.ascii.io"):
self.base_path = os.path.expanduser(base_path)
self.config_filename = '%s/config' % self.base_path
self.create_base_dir()
self.parse_config_file()
self._create_base_dir()
self._parse_config_file()
def create_base_dir(self):
if not os.path.isdir(self.base_dir_path):
os.mkdir(self.base_dir_path)
def _create_base_dir(self):
if not os.path.isdir(self.base_path):
os.mkdir(self.base_path)
def parse_config_file(self):
def _parse_config_file(self):
config = ConfigParser.RawConfigParser()
config.add_section('user')
config.add_section('api')

View File

@@ -14,6 +14,15 @@ import tty
def record_stream(stream, stdout_file):
recorder = StreamRecorder(stream, stdout_file)
return record(recorder)
def record_process(command, is_shell, stdout_file, stdin_file=None):
recorder = ProcessRecorder(command, is_shell, stdout_file, stdin_file)
return record(recorder)
def record(recorder):
start_time = time.time()
recorder.run()
end_time = time.time()
@@ -37,14 +46,6 @@ class StreamRecorder(object):
print line,
def record_process(command, is_shell, stdout_file, stdin_file=None):
recorder = ProcessRecorder(command, is_shell, stdout_file, stdin_file)
start_time = time.time()
recorder.run()
end_time = time.time()
return end_time - start_time
class ProcessRecorder(object):
'''Pseudo-terminal recorder.

49
tests/config_test.py Normal file
View File

@@ -0,0 +1,49 @@
from nose.tools import assert_equal
from nose.tools import assert_not_equal
from nose.tools import assert_raises
from nose.tools import raises
import os
import tempfile
import re
from config import Config
def create_config(config_file_content=None):
base_path = tempfile.mkdtemp()
if config_file_content:
with open(base_path + '/config', 'w') as f:
f.write(config_file_content)
return Config(base_path)
class TestConfig(object):
def test_api_url(self):
# defaults to http://ascii.io
config = create_config()
assert_equal('http://ascii.io', config.api_url)
# uses api.url from config file
config = create_config("[api]\nurl = bar")
assert_equal('bar', config.api_url)
# can be overriden by ASCII_IO_API_URL env var
os.environ['ASCII_IO_API_URL'] = 'foo'
assert_equal('foo', config.api_url)
del os.environ['ASCII_IO_API_URL']
def test_user_token(self):
# generates and saves new token in config file
config = create_config()
user_token = config.user_token
assert re.match('^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}', user_token)
assert os.path.isfile(config.base_path + '/config')
# reads existing token from config file
token = 'foo-bar-baz'
config = create_config("[user]\ntoken = %s" % token)
assert_equal(token, config.user_token)