Coverage for tests/test_cache.py : 79%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# # LSST Data Management System # Copyright 2008-2016 LSST Corporation. # # This product includes software developed by the # LSST Project (http://www.lsst.org/). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the LSST License Statement and # the GNU General Public License along with this program. If not, # see <http://www.lsstcorp.org/LegalNotices/>. #
"""Convert a number in the range [0, 1000) to words""" 0: "zero", 1: "one", 2: "two", 3: "three", 4: "four", 5: "five", 6: "six", 7: "seven", 8: "eight", 9: "nine", 10: "ten", 11: "eleven", 12: "twelve", 13: "thirteen", 14: "fourteen", 15: "fifteen", 16: "sixteen", 17: "seventeen", 18: "eighteen", 19: "nineteen", }[value] if value < 100: tens = value//10 ones = value % 10 return { 2: "twenty", 3: "thirty", 4: "forty", 5: "fifty", 6: "sixty", 7: "seventy", 8: "eighty", 9: "ninety", }[tens] + (("-" + numberToWords(ones)) if ones > 0 else "") assert value < 1000, "Value exceeds limit of 999" hundreds = value//100 rest = value % 100 return numberToWords(hundreds) + " hundred" + ((" " + numberToWords(rest)) if rest > 0 else "")
"""Tests of lsst.utils.Cache""" """Exercise the Cache
The `addFunction` should take a cache and number, and add the number (and its corresponding string) into the cache. """ # The new list of contents is smaller, but also reversed because we've gone through the cache # touching items.
"""Directly add key,value pairs into the cache with Cache.add"""
"""Exercise the lazy function call in Cache.operator()"""
# Check that the function call doesn't fire when we pull out something that's in there already
value = cache(index, trap) self.assertEqual(value, numberToWords(index))
# Check that this checking technique actually works...
import sys setup_module(sys.modules[__name__]) unittest.main() |