Example #1
0
    def test_str_to_bool_with_true_string_value(self):
        """
        Test the str_to_bool function with a string set to "True"
        """
        # GIVEN: A string set to "True"
        true_string = 'True'

        # WHEN: we convert it to a bool
        true_result = str_to_bool(true_string)

        # THEN: we should get back a true
        assert true_result is True, 'The result should be True'
Example #2
0
    def test_str_to_bool_with_yes_string_value(self):
        """
        Test the str_to_bool function with a string set to "yes"
        """
        # GIVEN: An string set to "yes"
        yes_string = 'yes'

        # WHEN: we convert it to a bool
        str_result = str_to_bool(yes_string)

        # THEN: we should get back a true
        assert str_result is True, 'The result should be True'
Example #3
0
    def test_str_to_bool_with_string_no(self):
        """
        Test the str_to_bool function with a string saying "NO"
        """
        # GIVEN: An string set to "NO"
        no_string = 'NO'

        # WHEN: we convert it to a bool
        str_result = str_to_bool(no_string)

        # THEN: we should get back a false
        assert str_result is False, 'The result should be False'
Example #4
0
    def test_str_to_bool_with_string_false(self):
        """
        Test the str_to_bool function with a string saying "false"
        """
        # GIVEN: A string set to "false"
        false_string = 'false'

        # WHEN: we convert it to a bool
        false_result = str_to_bool(false_string)

        # THEN: we should get back a false
        assert false_result is False, 'The result should be False'
Example #5
0
    def str_to_bool_with_invalid_test(self):
        """
        Test the str_to_bool function with a set of invalid inputs
        """
        # GIVEN: An integer value
        int_string = 1

        # WHEN: we convert it to a bool
        int_result = str_to_bool(int_string)

        # THEN: we should get back a false
        assert int_result is False, 'The result should be False'

        # GIVEN: An string value with completely invalid input
        invalid_string = 'my feet are wet'

        # WHEN: we convert it to a bool
        str_result = str_to_bool(invalid_string)

        # THEN: we should get back a false
        assert str_result is False, 'The result should be False'
Example #6
0
    def test_str_to_bool_with_true_string_value(self):
        """
        Test the str_to_bool function with a string set to "True"
        """
        # GIVEN: A string set to "True"
        true_string = 'True'

        # WHEN: we convert it to a bool
        true_result = str_to_bool(true_string)

        # THEN: we should get back a true
        self.assertTrue(true_result, 'The result should be True')
Example #7
0
    def test_str_to_bool_with_yes_string_value(self):
        """
        Test the str_to_bool function with a string set to "yes"
        """
        # GIVEN: An string set to "yes"
        yes_string = 'yes'

        # WHEN: we convert it to a bool
        str_result = str_to_bool(yes_string)

        # THEN: we should get back a true
        self.assertTrue(str_result, 'The result should be True')
Example #8
0
    def test_str_to_bool_with_invalid_string(self):
        """
        Test the str_to_bool function with an invalid string
        """
        # GIVEN: An string value with completely invalid input
        invalid_string = 'my feet are wet'

        # WHEN: we convert it to a bool
        str_result = str_to_bool(invalid_string)

        # THEN: we should get back a false
        self.assertFalse(str_result, 'The result should be False')
Example #9
0
    def test_str_to_bool_with_string_no(self):
        """
        Test the str_to_bool function with a string saying "NO"
        """
        # GIVEN: An string set to "NO"
        no_string = 'NO'

        # WHEN: we convert it to a bool
        str_result = str_to_bool(no_string)

        # THEN: we should get back a false
        self.assertFalse(str_result, 'The result should be False')
Example #10
0
    def str_to_bool_with_false_values_test(self):
        """
        Test the str_to_bool function with a set of false inputs
        """
        # GIVEN: A string set to "false"
        false_string = 'false'

        # WHEN: we convert it to a bool
        false_result = str_to_bool(false_string)

        # THEN: we should get back a false
        assert false_result is False, 'The result should be False'

        # GIVEN: An string set to "NO"
        no_string = 'NO'

        # WHEN: we convert it to a bool
        str_result = str_to_bool(no_string)

        # THEN: we should get back a false
        assert str_result is False, 'The result should be False'
Example #11
0
    def str_to_bool_with_true_values_test(self):
        """
        Test the str_to_bool function with a set of true inputs
        """
        # GIVEN: A string set to "True"
        true_string = 'True'

        # WHEN: we convert it to a bool
        true_result = str_to_bool(true_string)

        # THEN: we should get back a true
        assert true_result is True, 'The result should be True'

        # GIVEN: An string set to "yes"
        yes_string = 'yes'

        # WHEN: we convert it to a bool
        str_result = str_to_bool(yes_string)

        # THEN: we should get back a true
        assert str_result is True, 'The result should be True'
Example #12
0
    def test_str_to_bool_with_string_false(self):
        """
        Test the str_to_bool function with a string saying "false"
        """
        # GIVEN: A string set to "false"
        false_string = 'false'

        # WHEN: we convert it to a bool
        false_result = str_to_bool(false_string)

        # THEN: we should get back a false
        self.assertFalse(false_result, 'The result should be False')
Example #13
0
    def test_str_to_bool_with_integer(self):
        """
        Test the str_to_bool function with an integer input
        """
        # GIVEN: An integer value
        int_string = 1

        # WHEN: we convert it to a bool
        int_result = str_to_bool(int_string)

        # THEN: we should get back a false
        self.assertFalse(int_result, 'The result should be False')
Example #14
0
    def test_str_to_bool_with_invalid_string(self):
        """
        Test the str_to_bool function with an invalid string
        """
        # GIVEN: An string value with completely invalid input
        invalid_string = 'my feet are wet'

        # WHEN: we convert it to a bool
        str_result = str_to_bool(invalid_string)

        # THEN: we should get back a false
        assert str_result is False, 'The result should be False'
Example #15
0
    def test_str_to_bool_with_integer(self):
        """
        Test the str_to_bool function with an integer input
        """
        # GIVEN: An integer value
        int_string = 1

        # WHEN: we convert it to a bool
        int_result = str_to_bool(int_string)

        # THEN: we should get back a false
        assert int_result is False, 'The result should be False'
Example #16
0
    def test_str_to_bool_with_bool_false(self):
        """
        Test the str_to_bool function with boolean input of False
        """
        # GIVEN: A boolean value set to false
        false_boolean = False

        # WHEN: We "convert" it to a bool
        false_result = str_to_bool(false_boolean)

        # THEN: We should get back a True bool
        self.assertIsInstance(false_result, bool, 'The result should be a boolean')
        self.assertFalse(false_result, 'The result should be True')
Example #17
0
    def str_to_bool_with_bool_false_test(self):
        """
        Test the str_to_bool function with boolean input of False
        """
        # GIVEN: A boolean value set to false
        false_boolean = False

        # WHEN: We "convert" it to a bool
        false_result = str_to_bool(false_boolean)

        # THEN: We should get back a True bool
        self.assertIsInstance(false_result, bool, 'The result should be a boolean')
        self.assertFalse(false_result, 'The result should be True')
Example #18
0
    def test_str_to_bool_with_bool_false(self):
        """
        Test the str_to_bool function with boolean input of False
        """
        # GIVEN: A boolean value set to false
        false_boolean = False

        # WHEN: We "convert" it to a bool
        false_result = str_to_bool(false_boolean)

        # THEN: We should get back a True bool
        assert isinstance(false_result, bool), 'The result should be a boolean'
        assert false_result is False, 'The result should be True'
Example #19
0
    def test_str_to_bool_with_bool_true(self):
        """
        Test the str_to_bool function with boolean input of True
        """
        # GIVEN: A boolean value set to true
        true_boolean = True

        # WHEN: We "convert" it to a bool
        true_result = str_to_bool(true_boolean)

        # THEN: We should get back a True bool
        assert isinstance(true_result, bool), 'The result should be a boolean'
        assert true_result is True, 'The result should be True'
Example #20
0
    def str_to_bool_with_bool_true_test(self):
        """
        Test the str_to_bool function with boolean input of True
        """
        # GIVEN: A boolean value set to true
        true_boolean = True

        # WHEN: We "convert" it to a bool
        true_result = str_to_bool(true_boolean)

        # THEN: We should get back a True bool
        self.assertIsInstance(true_result, bool, 'The result should be a boolean')
        self.assertTrue(true_result, 'The result should be True')
Example #21
0
    def str_to_bool_with_bool_test(self):
        """
        Test the str_to_bool function with boolean input
        """
        # GIVEN: A boolean value set to true
        true_boolean = True

        # WHEN: We "convert" it to a bool
        true_result = str_to_bool(true_boolean)

        # THEN: We should get back a True bool
        assert isinstance(true_result, bool), 'The result should be a boolean'
        assert true_result is True, 'The result should be True'

        # GIVEN: A boolean value set to false
        false_boolean = False

        # WHEN: We "convert" it to a bool
        false_result = str_to_bool(false_boolean)

        # THEN: We should get back a True bool
        assert isinstance(false_result, bool), 'The result should be a boolean'
        assert false_result is False, 'The result should be True'
Example #22
0
 def _create_attr(self, master, element, value):
     """
     Create the attributes with the correct data types and name format
     """
     reject, master, element, value = self._translate_tags(master, element, value)
     if reject:
         return
     field = de_hump(element)
     tag = master + '_' + field
     if field in BOOLEAN_LIST:
         setattr(self, tag, str_to_bool(value))
     elif field in INTEGER_LIST:
         setattr(self, tag, int(value))
     else:
         # make string value unicode
         if not isinstance(value, str):
             value = str(str(value), 'utf-8')
         # None means an empty string so lets have one.
         if value == 'None':
             value = ''
         setattr(self, tag, str(value).strip().lstrip())
Example #23
0
 def _create_attr(self, master, element, value):
     """
     Create the attributes with the correct data types and name format
     """
     reject, master, element, value = self._translate_tags(master, element, value)
     if reject:
         return
     field = de_hump(element)
     tag = master + '_' + field
     if field in BOOLEAN_LIST:
         setattr(self, tag, str_to_bool(value))
     elif field in INTEGER_LIST:
         setattr(self, tag, int(value))
     else:
         # make string value unicode
         if not isinstance(value, str):
             value = str(str(value), 'utf-8')
         # None means an empty string so lets have one.
         if value == 'None':
             value = ''
         setattr(self, tag, str(value).strip().lstrip())