def test_load_example_jsc(self): """Loads example JSC string.""" self.assertIsNotNone( jsonsimpleconfig.loads(StringJscTestSuite.__example_jsc)) self.assertIsInstance( jsonsimpleconfig.loads(StringJscTestSuite.__example_jsc), jsonsimpleconfig.JscData)
def test_jsc_data_operations(self): """Loads example JSC string.""" data_one = jsonsimpleconfig.loads(JscDataTestSuite.__example_one_jsc) self.assertIsNotNone(data_one) self.assertIsInstance(data_one, jsonsimpleconfig.JscData) value = data_one.get_value(None, "variable_root") self.assertIsNotNone(value) self.assertEqual(value, "value_root") section = data_one.get_section() self.assertIsNotNone(section) self.assertEqual(section["variable_root"], "value_root") data_two = jsonsimpleconfig.loads(JscDataTestSuite.__example_two_jsc) data_one.merge(data_two) value = data_one.get_value(None, "variable_root") self.assertEqual(value, "value_root_two") section = data_two.get_section("section_two") self.assertIsNotNone(section) self.assertEqual(section["variable_section"], "value_section") self.assertEqual(data_one.get_value("section_two", "variable_section"), "value_section") data_one_json = jsonsimpleconfig.loads_json( JscDataTestSuite.__example_one_json) value = data_one_json.get_value(None, "variable_root") self.assertIsNotNone(value) self.assertEqual(value, "value_root_json") data_one.merge(data_one_json) value = data_one.get_value(None, "variable_root") self.assertEqual(value, "value_root_json")
def test_remove_multi_line_comments(self): """Remove multi line comment.""" self.assertIsNone( jsonsimpleconfig.loads("/* " + JscCommentsTestSuite.__example_jsc + " */")) self.assertIsNone( jsonsimpleconfig.loads("/* \n" + JscCommentsTestSuite.__example_jsc + "\n */")) self.assertIsInstance( jsonsimpleconfig.loads("// \n" + JscCommentsTestSuite.__example_jsc + "\n //"), jsonsimpleconfig.JscData)
def test_remove_one_line_comment(self): """Remove one line comment.""" self.assertIsNone( jsonsimpleconfig.loads("# " + JscCommentsTestSuite.__example_jsc)) self.assertIsNone( jsonsimpleconfig.loads("// " + JscCommentsTestSuite.__example_jsc)) self.assertIsNone( jsonsimpleconfig.loads("; " + JscCommentsTestSuite.__example_jsc)) self.assertEqual( '', jsonsimpleconfig.JscComments.strip_comments( "# " + JscCommentsTestSuite.__example_jsc)) self.assertEqual( '', jsonsimpleconfig.JscComments.strip_comments( "// " + JscCommentsTestSuite.__example_jsc)) self.assertEqual( '', jsonsimpleconfig.JscComments.strip_comments( "; " + JscCommentsTestSuite.__example_jsc))
def test_load_empty(self): """Loads empty string.""" self.assertIsNone(jsonsimpleconfig.loads(""))