<commit_before>import unittest, tempfile, os.path
from gitdh.config import Config, ConfigBranches
from gitdh.git import Git
from configparser import SectionProxy
from subprocess import check_output

class GitdhConfigTestCase(unittest.TestCase):

	def setUp(self):
		self.cStr = """
[Git]
RepositoryPath = /var/lib/gitolite/repositories/test.git

[Database]
Engine = sqlite
DatabaseFile = /var/lib/gitolite/data.sqlite
Table = commits

[master]
Path=/home/www/production

[development]
Path=/home/www/development
"""

	def test_branches(self):
		c = Config()
		c.read_string(self.cStr)

		self.assertTrue(isinstance(c.branches, ConfigBranches))

		self.assertEqual(len(c.branches), 2)

		self.assertFalse('feature-xyz' in c.branches)
		self.assertFalse('Git' in c.branches)
		self.assertFalse('Database' in c.branches)
		self.assertFalse('DEFAULT' in c.branches)
		self.assertTrue('development' in c.branches)
		self.assertTrue('master' in c.branches)

		self.assertRaises(KeyError, lambda: c.branches['feature-xyz'])
		self.assertRaises(KeyError, lambda: c.branches['Git'])
		self.assertRaises(KeyError, lambda: c.branches['Database'])
		self.assertRaises(KeyError, lambda: c.branches['DEFAULT'])

		self.assertSetEqual(set((i for i in c.branches)), set(('development', 'master')))

		self.assertTrue(isinstance(c.branches['development'], SectionProxy))
		self.assertTrue('Path' in c.branches['development'])
		self.assertFalse('External' in c.branches['development'])
		c['development']['External'] = 'False'
		self.assertTrue('External' in c.branches['development'])

	def test_file(self):
		f = tempfile.TemporaryFile(mode='w+')<commit_msg>Further test in tests/config.py (-command sections)<commit_after>import unittest, tempfile, os.path
from gitdh.config import Config, ConfigBranches
from gitdh.git import Git
from configparser import SectionProxy
from subprocess import check_output

class GitdhConfigTestCase(unittest.TestCase):

	def setUp(self):
		self.cStr = """
[Git]
RepositoryPath = /var/lib/gitolite/repositories/test.git

[Database]
Engine = sqlite
DatabaseFile = /var/lib/gitolite/data.sqlite
Table = commits

[master]
Path=/home/www/production

[development]
Path=/home/www/development

[crunch-command]
Mode = perfile
RegExp = \.php$
Command = eff_php_crunch ${f}
"""

	def test_branches(self):
		c = Config()
		c.read_string(self.cStr)

		self.assertTrue(isinstance(c.branches, ConfigBranches))

		self.assertEqual(len(c.branches), 2)

		self.assertNotIn('feature-xyz', c.branches)
		self.assertNotIn('Git', c.branches)
		self.assertNotIn('Database', c.branches)
		self.assertNotIn('DEFAULT', c.branches)
		self.assertNotIn('crunch-command', c.branches)
		self.assertIn('development', c.branches)
		self.assertIn('master', c.branches)

		self.assertRaises(KeyError, lambda: c.branches['feature-xyz'])
		self.assertRaises(KeyError, lambda: c.branches['Git'])
		self.assertRaises(KeyError, lambda: c.branches['Database'])
		self.assertRaises(KeyError, lambda: c.branches['DEFAULT'])
		self.assertRaises(KeyError, lambda: c.branches['crunch-command'])

		self.assertSetEqual(set((i for i in c.branches)), set(('development', 'master')))

		self.assertIsInstance(c.branches['development'], SectionProxy)
		self.assertIn('Path', c.branches['development'])

		self.assertNotIn('External', c.branches['development'])
		c['development']['External'] = 'False'
		self.assertIn('External', c.branches['development'])

	def test_command(self):
		c = Config()
		c.read_string(self.cStr)

		self.assertTrue('crunch-command' in c)
		sct = c['crunch-command']
		self.assertIsInstance(sct, SectionProxy)
		self.assertEqual(sct['Mode'], 'perfile')
		self.assertEqual(sct['RegExp'], '\.php$')
		self.assertEqual(sct['Command'], 'eff_php_crunch ${f}')

	def test_file(self):
		f = tempfile.TemporaryFile(mode='w+')
{'fraction_non_alphanumeric': 0.15229357798165138, 'fraction_numerical': 0.0005242463958060288, 'mean_word_length': 5.963503649635037, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '3060254', 'n_tokens_mistral': 1384, 'n_tokens_neox': 1269, 'n_words': 233}