Esempio n. 1
0
    def test_check_size_in_lazyLoad_and_no_lazyLoad(self):
        ks = file_stream('test/test.contd.conf')
        kon = from_stream(ks, False)
        ks1 = file_stream('test/test.contd.conf')
        kon1 = from_stream(ks1, True)

        self.assertEqual(len(kon) > 0, True)
        self.assertEqual(len(kon1) > 0, True)
        self.assertEqual(kon.is_empty(), False)
        self.assertEqual(kon1.is_empty(), False)
        self.assertEqual(len(kon1), len(kon1))
Esempio n. 2
0
    def test_escaping_and_unescaping_entries_and_save(self):
        ks = file_stream('test/test.config.ini')
        ks1 = file_stream('test/test.txt', ':', ',')
        kon = from_stream(ks)
        kon1 = from_stream(ks1)

        self.assertEqual(kon.get("Hobby"), "i don't know")
        self.assertEqual(kon1.get("Hobby"), kon.get("Hobby"))
        self.assertEqual(kon1.get("Hobby"), "i don't know")
        kon.save('test/test.config.ini')

        new_ks = file_stream('test/test.config.ini')
        new_kon = from_stream(new_ks, True)
        new_kon1 = from_file('test/test.txt', True, ':', ',')
        self.assertEqual(str(kon), str(kon))
        self.assertEqual(str(kon1), str(kon1))
Esempio n. 3
0
    def test_contains_with_lazy_load(self):
        ks = file_stream('test/test.comment.inf')
        ks.set_comment_prefix("[")
        kon = from_stream(ks)

        self.assertEqual(kon.contains("File"), True)
        self.assertEqual(kon.contains("Project"), True)
        self.assertEqual(kon.contains("Author"), True)
Esempio n. 4
0
    def test_invalid_argument_type_to_Konfiger_resolve(self):
        kstream = file_stream('test/test.comment.inf')
        kstream.set_comment_prefix("[")
        kon = from_stream(kstream)

        with self.assertRaises(TypeError) as context:
            kon.resolve(123)
        self.assertTrue(
            'io.github.thecarisma.konfiger: Invalid argument, the parameter must be a class object found '
            in str(context.exception))
Esempio n. 5
0
    def test_resolve_with_match_get_key_function(self):
        kstream = file_stream('test/test.comment.inf')
        kstream.set_comment_prefix("[")
        kon = from_stream(kstream)
        texts = Texts()
        kon.resolve(texts)

        self.assertEqual(texts.project, "konfiger")
        self.assertEqual(texts.Platform, "Cross Platform")
        self.assertEqual(texts.file, "test.comment.inf")
        self.assertEqual(texts.author, "Adewale Azeez")
Esempio n. 6
0
    def test_resolve_without_match_get_key_function(self):
        kstream = file_stream('test/test.comment.inf')
        kstream.set_comment_prefix("[")
        kon = from_stream(kstream)
        texts_flat = TextsFlat()
        kon.resolve(texts_flat)

        self.assertEqual(texts_flat.project, "")
        self.assertEqual(texts_flat.Platform, "Cross Platform")
        self.assertEqual(texts_flat.File, "test.comment.inf")
        self.assertEqual(texts_flat.author, "")
Esempio n. 7
0
    def test_read_multiline_entry_from_file_stream(self):
        ks = file_stream('test/test.contd.conf')
        kon = from_stream(ks)

        self.assertEqual(
            kon.get("ProgrammingLanguages").find(
                "Kotlin, NodeJS, Powershell, Python, Ring, Rust") > 0, True)
        self.assertEqual(kon.get("ProjectName"), "konfiger")
        self.assertNotEqual(
            kon.get("Description").endswith(
                " in other languages and off the Android platform."), False)
Esempio n. 8
0
    def test_should_throw_exceptions(self):
        self.assertRaises(TypeError, file_stream)

        with self.assertRaises(TypeError) as context:
            ks = file_stream(20)
        self.assertTrue(
            'Invalid argument expecting str found' in str(context.exception))

        with self.assertRaises(FileNotFoundError) as context:
            ks = file_stream("./tryer.ini")
        self.assertTrue('file does not exists' in str(context.exception))

        with self.assertRaises(TypeError) as context:
            ks = file_stream("./setup.py", ',', "==")
        self.assertTrue('Invalid argument for separator expecting char' in str(
            context.exception))

        with self.assertRaises(TypeError) as context:
            ks = string_stream(30)
        self.assertTrue(
            'Invalid argument expecting str found' in str(context.exception))
Esempio n. 9
0
    def test_error_tolerancy_in_file_stream(self):
        ks = file_stream("test/test.comment.inf")

        self.assertEqual(ks.is_error_tolerant(), False)
        while ks.has_next():
            with self.assertRaises(LookupError) as context:
                self.assertEqual(len(ks.next()[1]), 0)
            self.assertTrue(
                'Invalid entry detected near Line' in str(context.exception))
            break

        ks.error_tolerance(True)
        self.assertEqual(ks.is_error_tolerant(), True)
        while ks.has_next():
            self.assertNotEqual(ks.next()[1], None)
Esempio n. 10
0
    def test_resolve_with_changing_values_and_map_key_with_attach(self):
        kstream = file_stream('test/test.comment.inf')
        kstream.set_comment_prefix("[")
        kon = from_stream(kstream)
        texts = Texts()
        kon.attach(texts)

        self.assertNotEqual(texts.project, "konfiger")
        self.assertNotEqual(texts.Platform, "Cross Platform")
        self.assertNotEqual(texts.file, "test.comment.inf")
        self.assertNotEqual(texts.author, "Adewale Azeez")

        kon.put("Project", "konfiger-nodejs")
        kon.put("Platform", "Windows, Linux, Mac, Raspberry")
        kon.put("author", "Thecarisma")

        self.assertEqual(texts.project, "konfiger-nodejs")
        self.assertEqual("Windows" in texts.Platform, True)
        self.assertEqual("Linux" in texts.Platform, True)
        self.assertEqual("Mac" in texts.Platform, True)
        self.assertEqual("Raspberry" in texts.Platform, True)
        self.assertEqual(texts.author, "Thecarisma")
Esempio n. 11
0
    def test_detach_an_object_from_konfiger(self):
        kstream = file_stream('test/test.comment.inf')
        kstream.set_comment_prefix("[")
        kon = from_stream(kstream)
        texts = Texts()
        kon.resolve(texts)

        self.assertEqual(texts.project, "konfiger")
        self.assertEqual(texts.Platform, "Cross Platform")
        self.assertEqual(texts.file, "test.comment.inf")
        self.assertEqual(texts.author, "Adewale Azeez")
        self.assertEqual(texts, kon.detach())

        kon.put("Project", "konfiger-nodejs")
        kon.put("Platform", "Windows, Linux, Mac, Raspberry")
        kon.put("author", "Thecarisma")

        self.assertNotEqual(texts.project, "konfiger-nodejs")
        self.assertNotEqual("Windows" in texts.Platform, True)
        self.assertNotEqual("Linux" in texts.Platform, True)
        self.assertNotEqual("Mac" in texts.Platform, True)
        self.assertNotEqual("Raspberry" in texts.Platform, True)
        self.assertNotEqual(texts.author, "Thecarisma")
Esempio n. 12
0
 def test_the_single_pair_commenting_in_file_stream(self):
     ks = file_stream("test/test.txt", ':', ',')
     while ks.has_next():
         self.assertEqual(ks.next()[0].startswith("//"), False)
Esempio n. 13
0
 def test_the_single_pair_commenting_in_file_stream_1(self):
     ks = file_stream("test/test.comment.inf")
     ks.set_comment_prefix("[")
     while ks.has_next():
         self.assertEqual(ks.next()[0].startswith("["), False)
Esempio n. 14
0
 def test_validate_the_file_stream_value(self):
     ks = file_stream("test/test.config.ini", '=', '\n')
     while ks.has_next():
         self.assertNotEqual(ks.next(), None)
Esempio n. 15
0
 def test_should_successfully_initialize(self):
     self.assertNotEqual(file_stream("./setup.py"), None)
Esempio n. 16
0
 def test_read_multiline_entry_and_test_continuation_char_in_file_stream(
         self):
     ks = file_stream("test/test.contd.conf")
     while ks.has_next():
         self.assertEqual(ks.next()[1].endswith('\\'), False)