<commit_before>#!/usr/bin/python
from config import hostname, port, username, password

import preferences
import simplejson
import sogotests
import unittest
import utilities

class preferencesTest(unittest.TestCase):

    def _setTextPref(self, prefText = None ):
      """ set a text preference to a known value """
      self.prefs.set("autoReplyText", prefText)

      # make sure it was set correctly
      prefData = self.prefs.get("Vacation")
        
      try:
        self.assertEqual(prefData["autoReplyText"], prefText,
                  "%s != %s" % (prefData["autoReplyText"], prefText))
      except TypeError as err:
        self.fail("Preferences are probably hosed: %s" % (err))

    def setUp(self):
      self.prefs = preferences.preferences()

    def tearDown(self):
      self.prefs.set("autoReplyText", "")

    def testSetTextPreferences(self):
      """ Set/get a text preference - normal characters"""
      
      self._setTextPref("defaultText")

    def testSetTextPreferencesWeirdChars(self):
      """ Set/get a text preference - weird characters - used to crash on 1.3.12"""
      prefText = "weird data   \ ' \"; ^"
      self._setTextPref(prefText)

if __name__ == "__main__":
    sogotests.runTests()<commit_msg>remove 'except as' since it is not supported on python 2.5 (debian-lenny)<commit_after>#!/usr/bin/python
from config import hostname, port, username, password

import preferences
import simplejson
import sogotests
import unittest
import utilities

class preferencesTest(unittest.TestCase):

    def _setTextPref(self, prefText = None ):
      """ set a text preference to a known value """
      self.prefs.set("autoReplyText", prefText)

      # make sure it was set correctly
      prefData = self.prefs.get("Vacation")
        
      self.assertEqual(prefData["autoReplyText"], prefText,
                  "%s != %s" % (prefData["autoReplyText"], prefText))

    def setUp(self):
      self.prefs = preferences.preferences()

    def tearDown(self):
      self.prefs.set("autoReplyText", "")

    def testSetTextPreferences(self):
      """ Set/get a text preference - normal characters"""
      
      self._setTextPref("defaultText")

    def testSetTextPreferencesWeirdChars(self):
      """ Set/get a text preference - weird characters - used to crash on 1.3.12"""
      prefText = "weird data   \ ' \"; ^"
      self._setTextPref(prefText)

if __name__ == "__main__":
    sogotests.runTests()
{'fraction_non_alphanumeric': 0.11683006535947713, 'fraction_numerical': 0.004084967320261438, 'mean_word_length': 3.143824027072758, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1671764', 'n_tokens_mistral': 722, 'n_tokens_neox': 710, 'n_words': 191}