コード例 #1
0
 def test_keyerror_and_index_error(self):
     with suppress(KeyError):
         my_dict = {'key': 'value'}
         my_dict[4]
     self.assertEqual(my_dict, {'key': 'value'})
     with suppress(IndexError):
         my_list = ['item']
         my_list[1]
         self.assertEqual(my_list, ['item'])
コード例 #2
0
 def test_suppresses_parent_exceptions(self):
     with suppress(LookupError):
         my_dict = {'key': 'value'}
         my_dict[4]
     self.assertEqual(my_dict, {'key': 'value'})
     with suppress(LookupError):
         my_list = ['item']
         my_list[1]
         self.assertEqual(my_list, ['item'])
コード例 #3
0
ファイル: test_suppress.py プロジェクト: mmlakin/morsels
 def test_suppresses_parent_exceptions(self):
     with suppress(LookupError):
         my_dict = {"key": "value"}
         my_dict[4]
     self.assertEqual(my_dict, {"key": "value"})
     with suppress(LookupError):
         my_list = ["item"]
         my_list[1]
         self.assertEqual(my_list, ["item"])
コード例 #4
0
ファイル: test_suppress.py プロジェクト: mmlakin/morsels
 def test_keyerror_and_index_error(self):
     with suppress(KeyError):
         my_dict = {"key": "value"}
         my_dict[4]
     self.assertEqual(my_dict, {"key": "value"})
     with suppress(IndexError):
         my_list = ["item"]
         my_list[1]
         self.assertEqual(my_list, ["item"])
コード例 #5
0
 def test_catches_any_number_of_exceptions(self):
     with suppress(ValueError, TypeError):
         int('hello')
     with suppress(IndexError, TypeError):
         int(None)
     with self.assertRaises(KeyError):
         with suppress(IndexError, TypeError):
             {0: 1}[1]
     with suppress(ValueError, SystemError, IndexError, TypeError):
         ['item'][1]
コード例 #6
0
 def test_does_not_suppress_other_exceptions(self):
     with self.assertRaises(KeyError):
         with suppress(IndexError):
             my_dict = {'key': 'value'}
             my_dict[4]
         self.assertEqual(my_dict, {'key': 'value'})
     with self.assertRaises(IndexError):
         with suppress(KeyError):
             my_list = ['item']
             my_list[1]
             self.assertEqual(my_list, ['item'])
コード例 #7
0
 def test_suppress_specific_exception(self):
     with suppress(ValueError):
         x = 1
         int('hello')
         x = 2
     self.assertEqual(x, 1)
     with suppress(TypeError):
         x = 3
         int(None)
         x = 4
     self.assertEqual(x, 3)
コード例 #8
0
ファイル: test_suppress.py プロジェクト: mmlakin/morsels
 def test_does_not_suppress_other_exceptions(self):
     with self.assertRaises(KeyError):
         with suppress(IndexError):
             my_dict = {"key": "value"}
             my_dict[4]
         self.assertEqual(my_dict, {"key": "value"})
     with self.assertRaises(IndexError):
         with suppress(KeyError):
             my_list = ["item"]
             my_list[1]
             self.assertEqual(my_list, ["item"])
コード例 #9
0
ファイル: script.py プロジェクト: gtcooke94/snippets
from suppress import suppress

with suppress(KeyError, TypeError):
    a = 5
コード例 #10
0
 def test_allows_exception_to_be_viewed(self):
     with suppress(LookupError) as suppressed:
         my_dict = {'key': 'value'}
         my_dict[4]
     self.assertEqual(type(suppressed.exception), KeyError)
     self.assertEqual(type(suppressed.traceback), TracebackType)
コード例 #11
0
 def test_works_when_no_exception_raised(self):
     with suppress(Exception):
         x = 4
     self.assertEqual(x, 4)
コード例 #12
0
ファイル: large_run.py プロジェクト: Claycau/bigbrother
    states = splitLen

    sData = markov_anneal.splitActivityMax(oData.cd[0:50000], splitLen)
    
    scores = [0, 0]
    entropys = [0, 0]
    
    for i in range(2, 26):
        print "Models:" + str(i) 
        bestScore = -1
        bestModels = []
        bestData = []
        bestOut = []
        
        for j in range(2):
            suppress.suppress(2)
            bm, bd, out = markov_anneal.train(sData, i, states, obs, \
                                    iterations = 9, outliers = False, voidOutput = False)
            suppress.restore(2)
            mea = markov_anneal.modelErrorAverage(bm, bd, obs)
            entropy = markov_anneal.assignedDataEntropy(bd, out)
            score = (2**(sum(mea)/(len(mea) * 1.0)))*entropy
            
            if bestScore == -1 or score < bestScore:
                bestScore = score
                bestEnt = entropy
    
        print "   best score:" + str(bestScore) + "   best entropy:" + str(bestEnt)
        scores.append(bestScore)
        entropys.append(bestEnt)
    
コード例 #13
0
    states = splitLen

    sData = markov_anneal.splitActivityMax(oData.cd[0:50000], splitLen)

    scores = [0, 0]
    entropys = [0, 0]

    for i in range(2, 26):
        print "Models:" + str(i)
        bestScore = -1
        bestModels = []
        bestData = []
        bestOut = []

        for j in range(2):
            suppress.suppress(2)
            bm, bd, out = markov_anneal.train(sData, i, states, obs, \
                                    iterations = 9, outliers = False, voidOutput = False)
            suppress.restore(2)
            mea = markov_anneal.modelErrorAverage(bm, bd, obs)
            entropy = markov_anneal.assignedDataEntropy(bd, out)
            score = (2**(sum(mea) / (len(mea) * 1.0))) * entropy

            if bestScore == -1 or score < bestScore:
                bestScore = score
                bestEnt = entropy

        print "   best score:" + str(bestScore) + "   best entropy:" + str(
            bestEnt)
        scores.append(bestScore)
        entropys.append(bestEnt)