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.
import os
import unittest
from google.refine import refine
from google.refine import facet
PATH_TO_TEST_DATA = os.path.join('google', 'test', 'data')
from google.test import refinetest
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
class RefineServerTest(RefineTestCase):
class RefineServerTest(refinetest.RefineTestCase):
def test_init(self):
self.assertEqual(self.server.server,
'http://%s:%s' % (refine.REFINE_HOST, refine.REFINE_PORT))
@ -54,7 +33,7 @@ class RefineServerTest(RefineTestCase):
self.assertTrue(item in version_info)
class RefineTest(RefineTestCase):
class RefineTest(refinetest.RefineTestCase):
project_file = 'duplicates.csv'
def test_new_project(self):

View File

@ -14,35 +14,14 @@ 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')
from google.test import refinetest
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
class TutorialTestFacets(RefineTestCase):
class TutorialTestFacets(refinetest.RefineTestCase):
project_file = 'louisiana-elected-officials.csv'
def test_get_rows(self):
@ -144,7 +123,7 @@ class TutorialTestFacets(RefineTestCase):
self.assertEqual(cd.numeric_count, 548)
class TutorialTestEditing(RefineTestCase):
class TutorialTestEditing(refinetest.RefineTestCase):
project_file = 'louisiana-elected-officials.csv'
def test_editing(self):
@ -206,7 +185,7 @@ class TutorialTestEditing(RefineTestCase):
for row in response.rows:
response = self.project.star_row(row)
self.assertTrue(str(row.index + 1) in
response['historyEntry']['description'])
response['historyEntry']['description'])
# {5}, {6}, {7}
response = self.project.compute_facets(facet.StarredFacet(True))
self.assertEqual(len(response.facets[0].choices), 2) # true & false
@ -215,7 +194,7 @@ class TutorialTestEditing(RefineTestCase):
self.assertTrue('3 rows' in response['historyEntry']['description'])
class TutorialTestDuplicateDetection(RefineTestCase):
class TutorialTestDuplicateDetection(refinetest.RefineTestCase):
project_file = 'duplicates.csv'
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'
def test_transpose_columns_into_rows(self):
@ -310,7 +289,8 @@ class TutorialTestTransposeColumnsIntoRows(RefineTestCase):
self.assertEqual(row10['amount'], 113777303)
class TutorialTestTransposeFixedNumbeOfRowsIntoColumns(RefineTestCase):
class TutorialTestTransposeFixedNumbeOfRowsIntoColumns(
refinetest.RefineTestCase):
project_file = 'fixed-rows.csv'
project_file_options = {'split_into_columns': False,
'header_lines': 0}
@ -380,7 +360,7 @@ class TutorialTestTransposeFixedNumbeOfRowsIntoColumns(RefineTestCase):
response['historyEntry']['description'])
class TutorialTestTransposeVariableNumbeOfRowsIntoColumns(RefineTestCase):
class TutorialTestTransposeVariableNumbeOfRowsIntoColumns(refinetest.RefineTestCase):
project_file = 'variable-rows.csv'
project_file_options = {'split_into_columns': False,
'header_lines': 0}