Factor out RefineTestCase into test/refinetest.py

This commit is contained in:
Paul Makepeace 2011-04-26 15:13:25 -04:00
parent 25f144bf85
commit 7bcf52996a
3 changed files with 49 additions and 53 deletions

37
google/test/refinetest.py Normal file
View File

@ -0,0 +1,37 @@
#!/usr/bin/env python
"""
test_refine.py
These tests require a connection to a Refine server either at
http://127.0.0.1:3333/ or by specifying environment variables REFINE_HOST
and REFINE_PORT.
"""
# Copyright (c) 2011 Paul Makepeace, Real Programmers. All rights reserved.
import os
import unittest
from google.refine import refine
from google.refine import facet
PATH_TO_TEST_DATA = os.path.join('google', 'test', 'data')
class RefineTestCase(unittest.TestCase):
project_file = None
project_file_options = {}
project = None
# Section "2. Exploration using Facets": {1}, {2}
def setUp(self):
self.server = refine.RefineServer()
self.refine = refine.Refine(self.server)
if self.project_file:
self.project = self.refine.new_project(
os.path.join(PATH_TO_TEST_DATA, self.project_file),
**self.project_file_options)
def tearDown(self):
if self.project:
self.project.delete()
self.project = None

View File

@ -9,35 +9,14 @@ and REFINE_PORT.
# Copyright (c) 2011 Paul Makepeace, Real Programmers. All rights reserved. # Copyright (c) 2011 Paul Makepeace, Real Programmers. All rights reserved.
import os
import unittest import unittest
from google.refine import refine from google.refine import refine
from google.refine import facet from google.refine import facet
from google.test import refinetest
PATH_TO_TEST_DATA = os.path.join('google', 'test', 'data')
class RefineTestCase(unittest.TestCase): class RefineServerTest(refinetest.RefineTestCase):
project_file = None
project_file_options = {}
project = None
# Section "2. Exploration using Facets": {1}, {2}
def setUp(self):
self.server = refine.RefineServer()
self.refine = refine.Refine(self.server)
if self.project_file:
self.project = self.refine.new_project(
os.path.join(PATH_TO_TEST_DATA, self.project_file),
**self.project_file_options)
def tearDown(self):
if self.project:
self.project.delete()
self.project = None
class RefineServerTest(RefineTestCase):
def test_init(self): def test_init(self):
self.assertEqual(self.server.server, self.assertEqual(self.server.server,
'http://%s:%s' % (refine.REFINE_HOST, refine.REFINE_PORT)) 'http://%s:%s' % (refine.REFINE_HOST, refine.REFINE_PORT))
@ -54,7 +33,7 @@ class RefineServerTest(RefineTestCase):
self.assertTrue(item in version_info) self.assertTrue(item in version_info)
class RefineTest(RefineTestCase): class RefineTest(refinetest.RefineTestCase):
project_file = 'duplicates.csv' project_file = 'duplicates.csv'
def test_new_project(self): def test_new_project(self):

View File

@ -14,35 +14,14 @@ and REFINE_PORT.
# Copyright (c) 2011 Paul Makepeace, Real Programmers. All rights reserved. # Copyright (c) 2011 Paul Makepeace, Real Programmers. All rights reserved.
import os
import unittest import unittest
from google.refine import refine from google.refine import refine
from google.refine import facet from google.refine import facet
from google.test import refinetest
PATH_TO_TEST_DATA = os.path.join('google', 'test', 'data')
class RefineTestCase(unittest.TestCase): class TutorialTestFacets(refinetest.RefineTestCase):
project_file = None
project_file_options = {}
project = None
# Section "2. Exploration using Facets": {1}, {2}
def setUp(self):
self.server = refine.RefineServer()
self.refine = refine.Refine(self.server)
if self.project_file:
self.project = self.refine.new_project(
os.path.join(PATH_TO_TEST_DATA, self.project_file),
**self.project_file_options)
def tearDown(self):
if self.project:
self.project.delete()
self.project = None
class TutorialTestFacets(RefineTestCase):
project_file = 'louisiana-elected-officials.csv' project_file = 'louisiana-elected-officials.csv'
def test_get_rows(self): def test_get_rows(self):
@ -144,7 +123,7 @@ class TutorialTestFacets(RefineTestCase):
self.assertEqual(cd.numeric_count, 548) self.assertEqual(cd.numeric_count, 548)
class TutorialTestEditing(RefineTestCase): class TutorialTestEditing(refinetest.RefineTestCase):
project_file = 'louisiana-elected-officials.csv' project_file = 'louisiana-elected-officials.csv'
def test_editing(self): def test_editing(self):
@ -215,7 +194,7 @@ class TutorialTestEditing(RefineTestCase):
self.assertTrue('3 rows' in response['historyEntry']['description']) self.assertTrue('3 rows' in response['historyEntry']['description'])
class TutorialTestDuplicateDetection(RefineTestCase): class TutorialTestDuplicateDetection(refinetest.RefineTestCase):
project_file = 'duplicates.csv' project_file = 'duplicates.csv'
def test_duplicate_detection(self): def test_duplicate_detection(self):
@ -270,7 +249,7 @@ class TutorialTestDuplicateDetection(RefineTestCase):
]) ])
class TutorialTestTransposeColumnsIntoRows(RefineTestCase): class TutorialTestTransposeColumnsIntoRows(refinetest.RefineTestCase):
project_file = 'us_economic_assistance.csv' project_file = 'us_economic_assistance.csv'
def test_transpose_columns_into_rows(self): def test_transpose_columns_into_rows(self):
@ -310,7 +289,8 @@ class TutorialTestTransposeColumnsIntoRows(RefineTestCase):
self.assertEqual(row10['amount'], 113777303) self.assertEqual(row10['amount'], 113777303)
class TutorialTestTransposeFixedNumbeOfRowsIntoColumns(RefineTestCase): class TutorialTestTransposeFixedNumbeOfRowsIntoColumns(
refinetest.RefineTestCase):
project_file = 'fixed-rows.csv' project_file = 'fixed-rows.csv'
project_file_options = {'split_into_columns': False, project_file_options = {'split_into_columns': False,
'header_lines': 0} 'header_lines': 0}
@ -380,7 +360,7 @@ class TutorialTestTransposeFixedNumbeOfRowsIntoColumns(RefineTestCase):
response['historyEntry']['description']) response['historyEntry']['description'])
class TutorialTestTransposeVariableNumbeOfRowsIntoColumns(RefineTestCase): class TutorialTestTransposeVariableNumbeOfRowsIntoColumns(refinetest.RefineTestCase):
project_file = 'variable-rows.csv' project_file = 'variable-rows.csv'
project_file_options = {'split_into_columns': False, project_file_options = {'split_into_columns': False,
'header_lines': 0} 'header_lines': 0}