def test_it_should_not_change_python_path(self):
        original_paths = []
        for path in sys.path:
            original_paths.append(path)

        Utils.get_variables_from_file(os.path.abspath('sample.py'))

        self.assertEqual(original_paths, sys.path)
 def test_it_should_raise_exception_config_file_has_a_sintax_problem(self):
     f = open('sample.py', 'a')
     f.write('\nimport some_not_imported_module\n')
     f.close()
     try:
         Utils.get_variables_from_file(os.path.abspath('sample.py'))
         self.fail("it should not get here")
     except Exception, e:
         self.assertEqual("error interpreting config file 'sample.py': No module named some_not_imported_module", str(e))
 def test_it_should_support_utf8_content_on_temporary_file(self):
     filename = None
     try:
         filename = Utils.write_temporary_file('content çáéíóú'.decode('utf-8'), 'content_reference')
         self.assertEqual(open(filename, "r").read(), 'content çáéíóú')
     finally:
         if filename and os.path.exists(filename):
             os.unlink(filename)
 def test_it_should_create_a_temporary_file_with_the_given_content(self):
     filename = None
     try:
         filename = Utils.write_temporary_file('content', 'content_reference')
         self.assertTrue(filename.index('/tmp/') == 0)
         self.assertEqual(open(filename, "r").read(), 'content')
     finally:
         if filename and os.path.exists(filename):
             os.unlink(filename)
 def test_it_should_extract_variables_from_a_config_file_with_py_extension(self):
     variables = Utils.get_variables_from_file(os.path.abspath('sample.py'))
     self.assertEqual('root', variables['DATABASE_USER'])
     self.assertEqual('migration_example_env1', variables['ENV1_DATABASE_NAME'])
     self.assertEqual('migration_example', variables['DATABASE_NAME'])
     self.assertEqual('example', variables['DATABASE_MIGRATIONS_DIR'])
     self.assertEqual(True, variables['UTC_TIMESTAMP'])
     self.assertEqual('localhost', variables['DATABASE_HOST'])
     self.assertEqual('', variables['DATABASE_PASSWORD'])
 def test_it_should_delete_compiled_module_file(self):
     Utils.get_variables_from_file(os.path.abspath('sample.py'))
     self.assertFalse(os.path.exists(os.path.abspath('sample.pyc')))
 def test_it_should_raise_exception_config_file_not_exists(self):
     try:
         Utils.get_variables_from_file(os.path.abspath('unexistent.conf'))
         self.fail("it should not get here")
     except Exception, e:
         self.assertEqual("%s: file not found" % os.path.abspath('unexistent.conf'), str(e))
 def test_it_should_raise_exception_when_an_error_happens_on_writing_temporary_file(self, named_temporary_file_mock):
     try:
         Utils.write_temporary_file('content', 'content_reference')
         self.fail("it should not get here")
     except Exception, e:
         self.assertEqual('could not create temporary file for content_reference -> (some error)', str(e))
 def test_normalize_xsd_string_datatype_remains_untouched(self):
     literal = Literal('test', datatype="http://www.w3.org/2001/XMLSchema#string")
     result = Utils.get_normalized_n3(literal)
     expected = '"test"^^<http://www.w3.org/2001/XMLSchema#string>'
     self.assertEqual(result, expected)
 def test_normalize_boolean(self):
     literal = Literal('true', datatype="http://www.w3.org/2001/XMLSchema#boolean")
     result = Utils.get_normalized_n3(literal)
     expected = '"1"^^<http://www.w3.org/2001/XMLSchema#integer>'
     self.assertEqual(result, expected)
 def test_normalize_non_negative_integer(self):
     literal = Literal('1', datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger")
     result = Utils.get_normalized_n3(literal)
     expected = '"1"^^<http://www.w3.org/2001/XMLSchema#integer>'
     self.assertEqual(result, expected)