Esempio n. 1
0
    def test_type_casting(self):

        config = ConfigParser()
        config.parse("""
        (int) a = 10
        (list) names = Kieran, Martha, Mumbo
        (int) k = 10, 2
        (range) yes = 10, 20, 5
        (uuid.uuid4) guid =
        (list) b = one, two, three
        (list) c =
            one,
            two, three,
            four five
            six
        """)

        self.assertEqual(config.keys(),
                         {"a", "names", "k", "yes", "guid", "b", "c"})
        self.assertEqual(config["a"], 10)
        self.assertEqual(config["names"], ["Kieran", "Martha", "Mumbo"])
        self.assertEqual(config["k"], int("10", 2))
        self.assertEqual(config["yes"], range(10, 20, 5))
        self.assertEqual(config["b"], ["one", "two", "three"])
        self.assertEqual(
            config["c"],
            ["one", "two", "three", "four five{}six".format(os.linesep)])

        import uuid
        self.assertIsInstance(config["guid"], uuid.UUID)
Esempio n. 2
0
    def test_parse_string(self):

        config = ConfigParser()
        config.parse("""
        [section]
        a = 10
        """)

        self.assertEqual(config, {"section": {"a": "10"}})
Esempio n. 3
0
    def test_single_space_indentation_works(self):

        config = ConfigParser()
        config.parse("""
            a = something
             and this should add together too
            """)

        self.assertEqual(
            config["a"],
            "something{sep}and this should add together too".format(
                sep=os.linesep))
Esempio n. 4
0
    def test_equality_delimitation_of_properties(self):

        config = ConfigParser()

        config.parse("""
        a = 100
        b : 200
        (int) c = 1000
        (int) d : 2000
        e=123
        f:47432
        """)

        self.assertEqual(config.keys(), {"a", "b", "c", "d", "e", "f"})
Esempio n. 5
0
    def test_merging_configs(self):

        config = ConfigParser()

        config.parse("""
        [section]
        a = 10
        """)

        config.parse("""
        [section]
        b = 10
        """)

        self.assertEqual(config, {"section": {"a": "10", "b": "10"}})
Esempio n. 6
0
    def test_comments(self):
        """ Test that comments that are submitted to the config parser aren't picked up as a value or cause the
        parsing to error """

        config = ConfigParser()

        config.parse("""
        this line should not = include the comment # This is the comment
        Nor should this = one ; include this either...
        # These are obvious comments
        ;Yet you may be surprised
        #; Whhat If # I do this!
        ;# Or that?

        [WHAT SHALL HAPPEN] # nothing...
        """)

        self.assertEqual(
            set(config.keys()),
            {"this line should not", "Nor should this", "WHAT SHALL HAPPEN"})
        self.assertEqual(config["this line should not"], "include the comment")
        self.assertEqual(config["Nor should this"], "one")
        self.assertEqual(config["WHAT SHALL HAPPEN"], {})