[master/f21 v2] Fix int * Size operation and add tests (#1158792)

Brian C. Lane bcl at redhat.com
Wed Nov 5 16:43:07 UTC 2014


On Wed, Nov 05, 2014 at 09:29:29AM -0500, Anne Mulhern wrote:
> 
> 
> 
> 
> ----- Original Message -----
> > From: "Brian C. Lane" <bcl at redhat.com>
> > To: anaconda-patches at lists.fedorahosted.org
> > Sent: Tuesday, November 4, 2014 12:42:53 PM
> > Subject: [master/f21 v2] Fix int * Size operation and add tests (#1158792)
> > 
> > When Size is not on the left it needs to call the correct Decimal method
> > and make sure it returns a Size object. This also adds a test to make
> > sure the results of add, subtract, multiply, divide, modulo and power
> > return the current behavior.
> > ---
> >  blivet/size.py     |  1 +
> >  tests/size_test.py | 29 +++++++++++++++++++++++++++++
> >  2 files changed, 30 insertions(+)
> > 
> > diff --git a/blivet/size.py b/blivet/size.py
> > index 05a38b4..561c884 100644
> > --- a/blivet/size.py
> > +++ b/blivet/size.py
> > @@ -247,6 +247,7 @@ class Size(Decimal):
> >  
> >      def __mul__(self, other, context=None):
> >          return Size(Decimal.__mul__(self, other, context=context))
> > +    __rmul__ = __mul__
> >  
> >      def __div__(self, other, context=None):
> >          return Size(Decimal.__div__(self, other, context=context))
> > diff --git a/tests/size_test.py b/tests/size_test.py
> > index 9841b94..3bf3572 100644
> > --- a/tests/size_test.py
> > +++ b/tests/size_test.py
> > @@ -163,5 +163,34 @@ class SizeTestCase(unittest.TestCase):
> >          os.environ['LANG'] = saved_lang
> >          locale.setlocale(locale.LC_ALL, '')
> >  
> > +    def testArithmetic(self):
> > +        from decimal import Decimal
> > +        s = Size("2GiB")
> > +
> > +        # Make sure arithmatic operations with Size always result in Size
> > +        self.assertIsInstance(s+s, Size)
> > +        self.assertIsInstance(s-s, Size)
> > +        self.assertIsInstance(s*s, Size)
> > +        self.assertIsInstance(s/s, Size)
> > +        self.assertIsInstance(s**Size(2), Decimal)
> > +        self.assertIsInstance(s % Size(7), Size)
> > +
> > +
> > +        # Make sure operations with non-Size on the right result in Size
> > +        self.assertIsInstance(s+2, Size)
> > +        self.assertIsInstance(s-2, Size)
> > +        self.assertIsInstance(s*2, Size)
> > +        self.assertIsInstance(s/2, Size)
> > +        self.assertIsInstance(s**2, Decimal)
> > +        self.assertIsInstance(s % 127, Size)
> > +
> > +        # Make sure operations with non-Size on the left result in Size
> > +        self.assertIsInstance(2+s, Size)
> > +        self.assertIsInstance(2-s, Decimal)
> > +        self.assertIsInstance(2*s, Size)
> > +        self.assertIsInstance(2/s, Decimal)
> > +        self.assertIsInstance(2**Size(2), Decimal)
> > +        self.assertIsInstance(1024 % Size(127), Decimal)
> > +
> >  if __name__ == "__main__":
> >      unittest.main()
> > --
> > 1.9.3
> > 
> > _______________________________________________
> > anaconda-patches mailing list
> > anaconda-patches at lists.fedorahosted.org
> > https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
> > 
> 
> Except that the comments on the test no longer match the code, ack.

Oops, will fix. thanks.

-- 
Brian C. Lane | Anaconda Team | IRC: bcl #anaconda | Port Orchard, WA (PST8PDT)


More information about the anaconda-patches mailing list