#!/usr/bin/env python
#-*- coding: utf-8 -*-

#This software is distributed under the Creative Commons license (CC0) version 1.0. A copy of this license should have been distributed with this software.
#The license can also be read online: <https://creativecommons.org/publicdomain/zero/1.0/>. If this online license differs from the license provided with this software, the license provided with this software should be applied.

"""
Tests the behaviour of the validated dictionary.
"""

import configurationtype.validated_dictionary #The module we're testing.
import luna.tests #For parametrised tests.

class TestValidatedDictionary(luna.tests.TestCase):
	"""
	Collection of tests for the ``ValidatedDictionary``.
	"""

	@classmethod
	def setUp(self):
		"""
		Creates a fixture dictionary to test on.
		"""
		self.empty = configurationtype.validated_dictionary.ValidatedDictionary()

	def test_add_no_validation(self):
		"""
		Tests the simple case where the value is not validated.
		"""
		self.empty.add("apples", 4)
		#Test setting the item to a few various sorts of values to make sure it isn't validated.
		self.empty["apples"] = 4
		self.empty["apples"] = "3"
		self.empty["apples"] = None
		self.empty["apples"] = lambda x: x ** 2

	def test_add_validate_positive(self):
		"""
		Tests adding an item with a simple validation function.
		"""
		self.empty.add("pears", 4, lambda n: n > 0)
		#Test setting the item to a few good values.
		self.empty["pears"] = 2
		self.empty["pears"] = 1
		#Test setting the item to a few bad values.
		with self.assertRaises(ValueError):
			self.empty["pears"] = 0
		with self.assertRaises(ValueError):
			self.empty["pears"] = -5
@@ -1235,16 +1235,229 @@
 x ** 2%0A%0A
+%09def test_add_not_a_predicate(self):%0A%09%09%22%22%22%0A%09%09Tests what happens when you provide something that is not a predicate.%0A%09%09%22%22%22%0A%09%09with self.assertRaises(ValueError):%0A%09%09%09self.empty.add(%22oranges%22, 2, lambda x, y: x * y)%0A%0A
 %09def tes

Add test for adding items with non-predicate functions