<commit_before>#!/usr/bin/python
#
# Copyright (c) SAS Institute Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


"""
Test various methods of the RbuildConfiguration object.
"""

import os
from rbuild_test import rbuildhelp

import tempfile

from rbuild import rbuildcfg

class ConfigTest(rbuildhelp.RbuildHelper):
    def testWriteCheckoutFile(self):
        """
        Validate the output of the function used to write the rbuildrc
        in new product checkouts.
        """
        config = rbuildcfg.RbuildConfiguration()
        config.configLine('name <NAME>')
        config.configLine('contact <EMAIL>')
        config.configLine('repositoryMap []')
        config.configLine('repositoryMap foo.com https://repo.foo.com/conary/')
        config.configLine('repositoryMap bar.com https://dev.bar.com/conary/')
        config.configLine('repositoryUser foo.com foouser foopassword')
        config.configLine('repositoryUser bar.com baruser barpassword')
        config.configLine('user someuser somepassword')
        config.configLine('serverUrl http://myrbuilder.foo')
        config.configLine('signatureKey ASDF')
        config.configLine('signatureKeyMap foo FDSA')
        config.configLine('quiet True')

        dumpFile = tempfile.NamedTemporaryFile()
        config.writeCheckoutFile(dumpFile.name)
        dumpFile.seek(0)
        dump = dumpFile.read()

        expected = '''# contact (Default: None) (At `rbuild init': <EMAIL>)
# name (Default: None) (At `rbuild init': <NAME>)
# pluginDirs (Default: /usr/share/rbuild/plugins:~/.rbuild/plugins.d) (At `rbuild init': /usr/share/rbuild/plugins:~/.rbuild/plugins.d)
# quiet (Default: False) (At `rbuild init': True)
# repositoryMap (Default: [])
repositoryMap             foo.com                   https://repo.foo.com/conary/
repositoryMap             bar.com                   https://dev.bar.com/conary/
# repositoryUser (Default: []) (At `rbuild init': foo.com foouser foopassword, bar.com baruser barpassword)
# rmakePluginDirs (Default: /usr/share/rmake/plugins:~/.rmake/plugins.d) (At `rbuild init': /usr/share/rmake/plugins:~/.rmake/plugins.d)
# rmakeUrl (Default: None) (At `rbuild init': None)
# serverUrl (Default: None) (At `rbuild init': http://myrbuilder.foo)
# signatureKey (Default: None) (At `rbuild init': ASDF)
# signatureKeyMap (Default: []) (At `rbuild init': foo FDSA)
'''

        self.failUnlessEqual(dump, expected)
<commit_msg>Fix test broken by conary config changes<commit_after>#!/usr/bin/python
#
# Copyright (c) SAS Institute Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


"""
Test various methods of the RbuildConfiguration object.
"""

import os
from rbuild_test import rbuildhelp

import tempfile

from rbuild import rbuildcfg

class ConfigTest(rbuildhelp.RbuildHelper):
    def testWriteCheckoutFile(self):
        """
        Validate the output of the function used to write the rbuildrc
        in new product checkouts.
        """
        config = rbuildcfg.RbuildConfiguration()
        config.configLine('name <NAME>')
        config.configLine('contact <EMAIL>')
        config.configLine('repositoryMap []')
        config.configLine('repositoryMap bar.com https://dev.bar.com/conary/')
        config.configLine('repositoryMap foo.com https://repo.foo.com/conary/')
        config.configLine('repositoryUser bar.com baruser barpassword')
        config.configLine('repositoryUser foo.com foouser foopassword')
        config.configLine('user someuser somepassword')
        config.configLine('serverUrl http://myrbuilder.foo')
        config.configLine('signatureKey ASDF')
        config.configLine('signatureKeyMap foo FDSA')
        config.configLine('quiet True')

        dumpFile = tempfile.NamedTemporaryFile()
        config.writeCheckoutFile(dumpFile.name)
        dumpFile.seek(0)
        dump = dumpFile.read()

        expected = '''# contact (Default: None) (At `rbuild init': <EMAIL>)
# name (Default: None) (At `rbuild init': <NAME>)
# pluginDirs (Default: /usr/share/rbuild/plugins:~/.rbuild/plugins.d) (At `rbuild init': /usr/share/rbuild/plugins:~/.rbuild/plugins.d)
# quiet (Default: False) (At `rbuild init': True)
# repositoryMap (Default: [])
repositoryMap             bar.com                   https://dev.bar.com/conary/
repositoryMap             foo.com                   https://repo.foo.com/conary/
# repositoryUser (Default: []) (At `rbuild init': bar.com baruser barpassword, foo.com foouser foopassword)
# rmakePluginDirs (Default: /usr/share/rmake/plugins:~/.rmake/plugins.d) (At `rbuild init': /usr/share/rmake/plugins:~/.rmake/plugins.d)
# rmakeUrl (Default: None) (At `rbuild init': None)
# serverUrl (Default: None) (At `rbuild init': http://myrbuilder.foo)
# signatureKey (Default: None) (At `rbuild init': ASDF)
# signatureKeyMap (Default: []) (At `rbuild init': foo FDSA)
'''

        self.assertEqualWithDiff(dump, expected)

{'fraction_non_alphanumeric': 0.12073935899609971, 'fraction_numerical': 0.0016957775139901645, 'mean_word_length': 3.485171102661597, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 8, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, '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': '5700168', 'n_tokens_mistral': 1733, 'n_tokens_neox': 1705, 'n_words': 498}