Ejemplo n.º 1
0
 def test_dict_initialization(self):
     values_as_dict = {
         "name": "Martin D'vloper",
         "job": "Developer",
         "skill": "Elite",
         "employed": True,
         "age": 24,
         "foods": ["Apple", "Mango", 1234],
         "languages": {
             "perl": "Elite",
             "python": "Elite",
             "pascal": "Lame",
             "object_oriented": {
                 "best": ["C++", "C#"],
                 "great": "Java"
             }
         },
         "mysql": {
             "host": "localhost",
             "user": "******",
             "passwd": "vagrant",
             "db": "test"
         }
     }
     configuration.initialize(values_as_dict)
     self.assertEqual(configuration.name, "Martin D'vloper")
     self.assertEqual(configuration.job, "Developer")
     self.assertEqual(configuration.skill, "Elite")
     self.assertEqual(configuration.employed, True)
     self.assertEqual(configuration.age, 24)
     self.assertEqual(configuration.foods, ['Apple', 'Mango', 1234])
     self.assertEqual(configuration.languages.perl, 'Elite')
     self.assertEqual(configuration.languages.object_oriented.best,
                      ['C++', 'C#'])
     self.assertEqual(configuration.languages.object_oriented.great, 'Java')
Ejemplo n.º 2
0
 def test_mixed_yaml_initialization(self):
     configuration.initialize(_YAML_CONIFIGURATION_FILENAME,
                              junk='some junk')
     self.assertEqual(configuration.name, "Martin D'vloper")
     self.assertEqual(configuration.foods, ['Apple', 'Mango', 1234])
     self.assertEqual(configuration.languages.perl, 'Elite')
     self.assertEqual(configuration.languages.object_oriented.best,
                      ['C++', 'C#'])
     self.assertEqual(configuration.languages.object_oriented.great, 'Java')
     self.assertEqual(configuration.junk, 'some junk')
Ejemplo n.º 3
0
 def test_json_initialization(self):
     configuration.initialize(_JSON_CONIFIGURATION_FILENAME)
     self.assertEqual(configuration.name, "Martin D'vloper")
     self.assertEqual(configuration.job, "Developer")
     self.assertEqual(configuration.skill, "Elite")
     self.assertEqual(configuration.employed, True)
     self.assertEqual(configuration.age, 24)
     self.assertEqual(configuration.foods, ['Apple', 'Mango', 1234])
     self.assertEqual(configuration.languages.perl, 'Elite')
     self.assertEqual(configuration.languages.object_oriented.best,
                      ['C++', 'C#'])
     self.assertEqual(configuration.languages.object_oriented.great, 'Java')
Ejemplo n.º 4
0
    def setUp(self):
        configuration.initialize(_CONIFIGURATION_FILENAME)
        with make_non_query_executor(connect_to_db=False) as execute_query:
            db_name = configuration.mysql.db
            stmts = [
                _SQL_DROP_DB(db_name),
                _SQL_CREATE_DB(db_name),
            ]
            for sql in stmts:
                execute_query(sql)

        self.capitals = [
            (country, capital)
            for country, capital in csv.reader(open(_WORLD_CAPITALS_FILENAME))
        ]

        with make_non_query_executor() as execute_query:
            execute_query(_SQL_CREATE_TABLE)
            for country, capital in self.capitals:
                sql = _SQL_INSERT_CAPITAL(country=country.replace("'", "''"),
                                          capital=capital.replace("'", "''"))
                execute_query(sql)
Ejemplo n.º 5
0
    def test_direct_initalization(self):
        languages = {
            "perl": "Elite",
            "python": "Elite",
            "pascal": "Lame",
            "object_oriented": {
                "best": ["C++", "C#"],
                "great": "Java"
            }
        }

        configuration.initialize(name="Martin D'vloper",
                                 job="Developer",
                                 skill="Elite",
                                 employed=True,
                                 foods=["Apple", "Mango", 1234],
                                 languages=languages)
        self.assertEqual(configuration.name, "Martin D'vloper")
        self.assertEqual(configuration.job, "Developer")
        self.assertEqual(configuration.skill, "Elite")
        self.assertEqual(configuration.employed, True)
        self.assertEqual(configuration.foods, ['Apple', 'Mango', 1234])
        self.assertEqual(configuration.languages.object_oriented.best,
                         ['C++', 'C#'])
Ejemplo n.º 6
0
 def test_non_existing_filename(self):
     with self.assertRaises(ConfigurationError):
         configuration.initialize("invalid.nonexisting")
Ejemplo n.º 7
0
 def test_bad_json(self):
     with self.assertRaises(ConfigurationError):
         configuration.initialize(_BAD_JSON_CONIFIGURATION_FILENAME)