This fork extends the command line interface (CLI) and is distributed as a convenient one-file-executable (Windows, Linux, Mac). It is also available via Docker Hub, PyPI and Binder.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

81 lines
2.5 KiB

  1. #!/usr/bin/env python
  2. """
  3. test_refine.py
  4. These tests require a connection to a Refine server either at
  5. http://127.0.0.1:3333/ or by specifying environment variables
  6. OPENREFINE_HOST and OPENREFINE_PORT.
  7. """
  8. # Copyright (c) 2011 Paul Makepeace, Real Programmers. All rights reserved.
  9. import csv
  10. import unittest
  11. from google.refine import refine
  12. from tests import refinetest
  13. class RefineServerTest(refinetest.RefineTestCase):
  14. def test_init(self):
  15. server_url = 'http://' + refine.REFINE_HOST
  16. if refine.REFINE_PORT != '80':
  17. server_url += ':' + refine.REFINE_PORT
  18. self.assertEqual(self.server.server, server_url)
  19. self.assertEqual(refine.RefineServer.url(), server_url)
  20. # strip trailing /
  21. server = refine.RefineServer('http://refine.example/')
  22. self.assertEqual(server.server, 'http://refine.example')
  23. def test_list_projects(self):
  24. projects = self.refine.list_projects()
  25. self.assertTrue(isinstance(projects, dict))
  26. def test_get_version(self):
  27. version_info = self.server.get_version()
  28. for item in ('revision', 'version', 'full_version', 'full_name'):
  29. self.assertTrue(item in version_info)
  30. def test_version(self):
  31. self.assertTrue(self.server.version in ('2.0', '2.1', '2.5'))
  32. class RefineTest(refinetest.RefineTestCase):
  33. project_file = 'duplicates.csv'
  34. def test_new_project(self):
  35. self.assertTrue(isinstance(self.project, refine.RefineProject))
  36. def test_wait_until_idle(self):
  37. self.project.wait_until_idle() # should just return
  38. def test_get_models(self):
  39. self.assertEqual(self.project.key_column, 'email')
  40. self.assertTrue('email' in self.project.columns)
  41. self.assertTrue('email' in self.project.column_order)
  42. self.assertEqual(self.project.column_order['name'], 1)
  43. def test_delete_project(self):
  44. self.assertTrue(self.project.delete())
  45. def test_open_export(self):
  46. fp = refine.RefineProject(self.project.project_url()).export()
  47. line = fp.next()
  48. self.assertTrue('email' in line)
  49. for line in fp:
  50. self.assertTrue('M' in line or 'F' in line)
  51. fp.close()
  52. def test_open_export_csv(self):
  53. fp = refine.RefineProject(self.project.project_url()).export()
  54. csv_fp = csv.reader(fp, dialect='excel-tab')
  55. row = csv_fp.next()
  56. self.assertTrue(row[0] == 'email')
  57. for row in csv_fp:
  58. self.assertTrue(row[3] == 'F' or row[3] == 'M')
  59. fp.close()
  60. if __name__ == '__main__':
  61. unittest.main()