<commit_before>#
# Copyright (C) 2012, 2013 <NAME> <ssato at redhat.com>
# License: MIT
#
import anyconfig.api as A
import anyconfig.tests.common as C

import anyconfig.backend.ini_ as BINI
import anyconfig.backend.json_ as BJSON
import anyconfig.backend.xml_ as BXML
import anyconfig.backend.yaml_ as BYAML
import anyconfig.backend.properties_ as BPROP

import os
import os.path
import unittest


class Test_10_pure_functions(unittest.TestCase):

    def test_10_find_loader__w_forced_type(self):
        cpath = "dummy.conf"

        # These parsers should be supported.
        self.assertEquals(A.find_loader(cpath, "ini"), BINI.IniConfigParser)
        self.assertEquals(A.find_loader(cpath, "json"), BJSON.JsonConfigParser)

        if BYAML.SUPPORTED:
            self.assertEquals(A.find_loader(cpath, "yaml"),
                              BYAML.YamlConfigParser)

        if BXML.SUPPORTED:
            self.assertEquals(A.find_loader(cpath, "xml"),
                              BXML.XmlConfigParser)

        if BPROP.SUPPORTED:
            self.assertEquals(A.find_loader(cpath, "properties"),
                              BPROP.PropertiesParser)

    def test_20_find_loader__by_file(self):
        self.assertEquals(A.find_loader("dummy.ini"), BINI.IniConfigParser)
        self.assertEquals(A.find_loader("dummy.json"), BJSON.JsonConfigParser)
        self.assertEquals(A.find_loader("dummy.jsn"), BJSON.JsonConfigParser)

        if BYAML.SUPPORTED:
            self.assertEquals(A.find_loader("dummy.yaml"),
                              BYAML.YamlConfigParser)
            self.assertEquals(A.find_loader("dummy.yml"),
                              BYAML.YamlConfigParser)

        if BXML.SUPPORTED:
            self.assertEquals(A.find_loader("dummy.xml"),
                              BXML.XmlConfigParser)

        if BPROP.SUPPORTED:
            self.assertEquals(A.find_loader("dummy.properties"),
                              BPROP.PropertiesParser)

    def test_30_dumps_and_loads(self):
        a = dict(name="a", a=1, b=dict(b=[1, 2], c="C"))
        a1 = A.loads(A.dumps(a, "json"), "json")

        self.assertEquals(a1["name"],   a["name"])
        self.assertEquals(a1["a"],      a["a"])
        self.assertEquals(a1["b"]["b"], a["b"]["b"])
        self.assertEquals(a1["b"]["c"], a["b"]["c"])

    def test_30_dumps_and_loads__w_options(self):<commit_msg>remove references to properties backend module<commit_after>#
# Copyright (C) 2012, 2013 <NAME> <ssato at redhat.com>
# License: MIT
#
import anyconfig.api as A
import anyconfig.tests.common as C

import anyconfig.backend.ini_ as BINI
import anyconfig.backend.json_ as BJSON
import anyconfig.backend.xml_ as BXML
import anyconfig.backend.yaml_ as BYAML

import os
import os.path
import unittest


class Test_10_pure_functions(unittest.TestCase):

    def test_10_find_loader__w_forced_type(self):
        cpath = "dummy.conf"

        # These parsers should be supported.
        self.assertEquals(A.find_loader(cpath, "ini"), BINI.IniConfigParser)
        self.assertEquals(A.find_loader(cpath, "json"), BJSON.JsonConfigParser)

        if BYAML.SUPPORTED:
            self.assertEquals(A.find_loader(cpath, "yaml"),
                              BYAML.YamlConfigParser)

        if BXML.SUPPORTED:
            self.assertEquals(A.find_loader(cpath, "xml"),
                              BXML.XmlConfigParser)

    def test_20_find_loader__by_file(self):
        self.assertEquals(A.find_loader("dummy.ini"), BINI.IniConfigParser)
        self.assertEquals(A.find_loader("dummy.json"), BJSON.JsonConfigParser)
        self.assertEquals(A.find_loader("dummy.jsn"), BJSON.JsonConfigParser)

        if BYAML.SUPPORTED:
            self.assertEquals(A.find_loader("dummy.yaml"),
                              BYAML.YamlConfigParser)
            self.assertEquals(A.find_loader("dummy.yml"),
                              BYAML.YamlConfigParser)

        if BXML.SUPPORTED:
            self.assertEquals(A.find_loader("dummy.xml"),
                              BXML.XmlConfigParser)

    def test_30_dumps_and_loads(self):
        a = dict(name="a", a=1, b=dict(b=[1, 2], c="C"))
        a1 = A.loads(A.dumps(a, "json"), "json")

        self.assertEquals(a1["name"],   a["name"])
        self.assertEquals(a1["a"],      a["a"])
        self.assertEquals(a1["b"]["b"], a["b"]["b"])
        self.assertEquals(a1["b"]["c"], a["b"]["c"])

    def test_30_dumps_and_loads__w_options(self):
{'fraction_non_alphanumeric': 0.12466487935656836, 'fraction_numerical': 0.01161751563896336, 'mean_word_length': 2.5816, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6680768', 'n_tokens_mistral': 1444, 'n_tokens_neox': 1395, 'n_words': 233}