示例#1
0
 def test_cast_get_method(self):
     """Ensure that the get method can cast"""
     envdict = EnvDict({'DEBUG': '1'})
     self.assertEqual(True, envdict.get('DEBUG', cast=bool))
     self.assertEqual(True, envdict.get('MISSING', True, cast=bool))
     # If the key is missing the default should not be cast
     self.assertEqual('True', envdict.get('MISSING', 'True', cast=bool))
示例#2
0
 def test_cast_get_method(self):
     """Ensure that the get method can cast"""
     envdict = EnvDict({'DEBUG': '1'})
     self.assertEqual(True, envdict.get('DEBUG', cast=bool))
     self.assertEqual(True, envdict.get('MISSING', True, cast=bool))
     # If the key is missing the default should not be cast
     self.assertEqual('True', envdict.get('MISSING', 'True', cast=bool))
示例#3
0
 def test_boolean_cast(self):
     self.assertTrue(
         EnvDict({'DEBUG': 'True'}, schema={'DEBUG': bool})['DEBUG'])
     self.assertTrue(
         EnvDict({'DEBUG': 'true'}, schema={'DEBUG': bool})['DEBUG'])
     self.assertTrue(
         EnvDict({'DEBUG': 'on'}, schema={'DEBUG': bool})['DEBUG'])
     self.assertTrue(
         EnvDict({'DEBUG': '1'}, schema={'DEBUG': bool})['DEBUG'])
     self.assertFalse(
         EnvDict({'DEBUG': 'False'}, schema={'DEBUG': bool})['DEBUG'])
     self.assertFalse(
         EnvDict({'DEBUG': 'off'}, schema={'DEBUG': bool})['DEBUG'])
     self.assertFalse(
         EnvDict({'DEBUG': 'debug'}, schema={'DEBUG': bool})['DEBUG'])
示例#4
0
 def test_recasting(self):
     envdict = EnvDict({'DEBUG': '1'})
     self.assertEqual('1', envdict['DEBUG'])
     envdict.recast(schema={'DEBUG': int})
     self.assertEqual(1, envdict['DEBUG'])
示例#5
0
 def test_update_casts(self):
     """Update the cast functions on init"""
     envdict = EnvDict({'DEBUG': '1'}, casts={'mycast': Decimal})
     self.assertEqual(envdict.get('DEBUG', cast='mycast'), Decimal('1'))
示例#6
0
 def test_cast_pop_method(self):
     """Ensure that the pop method can cast"""
     envdict = EnvDict({'DEBUG': '1'})
     self.assertEqual(True, envdict.pop('DEBUG', cast=bool))
     self.assertEqual(True, envdict.pop('MISSING', True, cast=bool))
     self.assertEqual('True', envdict.pop('MISSING', 'True', cast=bool))
示例#7
0
 def test_missing_key(self):
     """Ensure the defaults work as expected"""
     self.assertTrue(EnvDict({}).get('DEBUG', True))
     self.assertFalse(EnvDict({}).get('DEBUG', False))
示例#8
0
 def test_missing_cast_cast(self):
     """Missing cast should default to a string"""
     self.assertTrue(
         isinstance(
             EnvDict({'DEBUG': '1'}, schema={'DEBUG': 'kjkjdjk'})['DEBUG'],
             str))
示例#9
0
 def test_dict_cast(self):
     self.assertTrue(
         isinstance(
             EnvDict({'SOMEDICT': 'a=a,name=tester'},
                     schema={'SOMEDICT': dict})['SOMEDICT'], dict))
示例#10
0
 def test_list_cast(self):
     self.assertTrue(
         isinstance(
             EnvDict({'MYLIST': '1'}, schema={'MYLIST': list})['MYLIST'],
             list))
示例#11
0
 def test_float_cast(self):
     self.assertTrue(
         isinstance(
             EnvDict({'FLOAT': '1'}, schema={'FLOAT': float})['FLOAT'],
             float))
示例#12
0
 def test_decimal_cast(self):
     self.assertTrue(
         isinstance(
             EnvDict({'DECIMAL': '1'},
                     schema={'DECIMAL': 'decimal'})['DECIMAL'], Decimal))
示例#13
0
 def test_recasting(self):
     envdict = EnvDict({'DEBUG': '1'})
     self.assertEqual('1', envdict['DEBUG'])
     envdict.recast(schema={'DEBUG': int})
     self.assertEqual(1, envdict['DEBUG'])
示例#14
0
 def test_update_casts(self):
     """Update the cast functions on init"""
     envdict = EnvDict({'DEBUG': '1'}, casts={'mycast': Decimal})
     self.assertEqual(envdict.get('DEBUG', cast='mycast'), Decimal('1'))
示例#15
0
 def test_cast_pop_method(self):
     """Ensure that the pop method can cast"""
     envdict = EnvDict({'DEBUG': '1'})
     self.assertEqual(True, envdict.pop('DEBUG', cast=bool))
     self.assertEqual(True, envdict.pop('MISSING', True, cast=bool))
     self.assertEqual('True', envdict.pop('MISSING', 'True', cast=bool))