From c917d22db5bc99a5686046a52b81be2495017169 Mon Sep 17 00:00:00 2001 From: blitzmann Date: Fri, 23 Feb 2018 01:00:43 -0500 Subject: [PATCH] tox fixes for the roman library to prevent travis from yelling at us --- gui/utils/roman.py | 48 ++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/gui/utils/roman.py b/gui/utils/roman.py index a8628e3c8..0a75ccadc 100644 --- a/gui/utils/roman.py +++ b/gui/utils/roman.py @@ -16,26 +16,39 @@ http://www.python.org/2.1.1/license.html import re -#Define exceptions -class RomanError(Exception): pass -class OutOfRangeError(RomanError): pass -class NotIntegerError(RomanError): pass -class InvalidRomanNumeralError(RomanError): pass -#Define digit mapping -romanNumeralMap = (('M', 1000), +# Define exceptions +class RomanError(Exception): + pass + + +class OutOfRangeError(RomanError): + pass + + +class NotIntegerError(RomanError): + pass + + +class InvalidRomanNumeralError(RomanError): + pass + + +# Define digit mapping +romanNumeralMap = (('M', 1000), ('CM', 900), - ('D', 500), + ('D', 500), ('CD', 400), - ('C', 100), + ('C', 100), ('XC', 90), - ('L', 50), + ('L', 50), ('XL', 40), - ('X', 10), + ('X', 10), ('IX', 9), - ('V', 5), + ('V', 5), ('IV', 4), - ('I', 1)) + ('I', 1)) + def toRoman(n): """convert integer to Roman numeral""" @@ -51,7 +64,8 @@ def toRoman(n): n -= integer return result -#Define pattern to detect valid Roman numerals + +# Define pattern to detect valid Roman numerals romanNumeralPattern = re.compile(""" ^ # beginning of string M{0,4} # thousands - 0 to 4 M's @@ -62,7 +76,8 @@ romanNumeralPattern = re.compile(""" (IX|IV|V?I{0,3}) # ones - 9 (IX), 4 (IV), 0-3 (0 to 3 I's), # or 5-8 (V, followed by 0 to 3 I's) $ # end of string - """ ,re.VERBOSE) + """, re.VERBOSE) + def fromRoman(s): """convert Roman numeral to integer""" @@ -74,8 +89,7 @@ def fromRoman(s): result = 0 index = 0 for numeral, integer in romanNumeralMap: - while s[index:index+len(numeral)] == numeral: + while s[index:index + len(numeral)] == numeral: result += integer index += len(numeral) return result -