From wereapwhatwesow at gmail.com Mon Dec 6 21:59:32 2010 From: wereapwhatwesow at gmail.com (Steve Young) Date: Mon, 6 Dec 2010 14:59:32 -0600 Subject: [omaha] December meeting Message-ID: 1. This is a little early, but our next meeting is on the 20th, the week of Christmas. I will be out of town that week and wanted to check everyone's schedules. (No pressure, but I could do next Monday, the 13th if anyone is interested.) 2. I have just finished the Python Koans!! It was a good learning experience, and picked up a few good tools along the way. 3. I am still trying to get a weekly lunch meetup going: 1. Who is interested? 2. Where to meet? 3. What to do? 4. Maybe start after the holidays? -- --Steve Young From wereapwhatwesow at gmail.com Sun Dec 12 00:19:42 2010 From: wereapwhatwesow at gmail.com (Steve Young) Date: Sat, 11 Dec 2010 17:19:42 -0600 Subject: [omaha] expand my understanding... Message-ID: I am going thru a book on testing, and ran across the following code: class multiply: def __init__(self, *operands): self.operands = operands def evaluate(self, bindings): vals = [x.evaluate(bindings) for x in self.operands] if len(vals) < 2: raise ValueError('multiply without at least two ' 'operands is meaningless') result = 1.0 for val in vals: result *= val return result The line " vals = [x.evaluate(bindings) for x in self.operands]" appears to take operand(s) and put them into a list. I can't get my brain to understand it. operands are any number of floating point numbers. Any tips greatly appreciated. -- Steve Young From jeffh at dundeemt.com Sun Dec 12 05:38:16 2010 From: jeffh at dundeemt.com (Jeff Hinrichs - DM&T) Date: Sat, 11 Dec 2010 22:38:16 -0600 Subject: [omaha] expand my understanding... In-Reply-To: References: Message-ID: You are correct. It's a list comprehension. L=[1,2,3] print [str(x) for x in L] Prints out ['1', '2','3'] Jeff On Dec 11, 2010 5:19 PM, "Steve Young" wrote: > I am going thru a book on testing, and ran across the following code: > > class multiply: > def __init__(self, *operands): > self.operands = operands > > def evaluate(self, bindings): > vals = [x.evaluate(bindings) for x in self.operands] > > if len(vals) < 2: > raise ValueError('multiply without at least two ' > 'operands is meaningless') > > result = 1.0 > for val in vals: > result *= val > > return result > > The line " vals = [x.evaluate(bindings) for x in self.operands]" > appears to take operand(s) and put them into a list. I can't get my brain > to understand it. operands are any number of floating point numbers. Any > tips greatly appreciated. > > > -- > Steve Young > _______________________________________________ > Omaha Python Users Group mailing list > Omaha at python.org > http://mail.python.org/mailman/listinfo/omaha > http://www.OmahaPython.org From wereapwhatwesow at gmail.com Sun Dec 12 06:43:46 2010 From: wereapwhatwesow at gmail.com (Steve Young) Date: Sat, 11 Dec 2010 23:43:46 -0600 Subject: [omaha] expand my understanding... In-Reply-To: References: Message-ID: Thanks Jeff. Good to hear from you, haven't seen you in awhile. I just figured out that the way the test was running, the operands were mock objects. So when m is instantiated with m = multiply(p1, p2) self.operands becomes a tuple containing two mock objects. (I originally thought it was a tuple containing the numbers, and x.evaluate(bindings) was doing some recursive wierdness with the evaluate function. Once I realized that x.evaluate... was returning the mocker result values everything became clearer.) To finish my explanation if anyone is still reading: Then when m.evaluate({}) is called, the x.evaluate(bindings) loads the mocker.result values to replace the mock objects with the mocker.result numbers. It works like a normal list comprehension: The first time thru the list comprehension x = p1. Since the test code for p1.evaluate({}) is 97.43, it puts 97.43 as the first item in vals list. It then does the same for p2. So vals = [97.43, -16.25] Maybe I am spending too much time on a not so great example, because I see how the test works, but if I try and use the multiply class normally, and don't pass it mock objects as the operands (ie pass it numbers), then I get an attribute error that saying the object has no attribute 'evaluate'. the test code looks like this: from mocker import Mocker mocker = Mocker() p1 = mocker.mock() p1.evaluate({}) mocker.result(97.43) p2 = mocker.mock() p2.evaluate({}) mocker.result(-16.25) mocker.replay() m = multiply(p1, p2) round(m.evaluate({}),2) (the above code was originally in a docstring, I changed it and added it to the bottom of my multiply module. it isn't a proper test this way...) On Sat, Dec 11, 2010 at 10:38 PM, Jeff Hinrichs - DM&T wrote: > You are correct. It's a list comprehension. > L=[1,2,3] > print [str(x) for x in L] > > Prints out > ['1', '2','3'] > > Jeff > On Dec 11, 2010 5:19 PM, "Steve Young" wrote: > > I am going thru a book on testing, and ran across the following code: > > > > class multiply: > > def __init__(self, *operands): > > self.operands = operands > > > > def evaluate(self, bindings): > > vals = [x.evaluate(bindings) for x in self.operands] > > > > if len(vals) < 2: > > raise ValueError('multiply without at least two ' > > 'operands is meaningless') > > > > result = 1.0 > > for val in vals: > > result *= val > > > > return result > > > > The line " vals = [x.evaluate(bindings) for x in self.operands]" > > appears to take operand(s) and put them into a list. I can't get my brain > > to understand it. operands are any number of floating point numbers. Any > > tips greatly appreciated. > > > > > > -- > > Steve Young > > _______________________________________________ > > Omaha Python Users Group mailing list > > Omaha at python.org > > http://mail.python.org/mailman/listinfo/omaha > > http://www.OmahaPython.org > _______________________________________________ > Omaha Python Users Group mailing list > Omaha at python.org > http://mail.python.org/mailman/listinfo/omaha > http://www.OmahaPython.org > -- Steve Young From jeffh at dundeemt.com Sun Dec 12 06:53:48 2010 From: jeffh at dundeemt.com (Jeff Hinrichs - DM&T) Date: Sat, 11 Dec 2010 23:53:48 -0600 Subject: [omaha] expand my understanding... In-Reply-To: References: Message-ID: Can you paste the code at the problem? On Dec 11, 2010 11:43 PM, "Steve Young" wrote: > Thanks Jeff. Good to hear from you, haven't seen you in awhile. > > I just figured out that the way the test was running, the operands were mock > objects. So when m is instantiated with > m = multiply(p1, p2) > self.operands becomes a tuple containing two mock objects. (I originally > thought it was a tuple containing the numbers, and x.evaluate(bindings) was > doing some recursive wierdness with the evaluate function. Once I realized > that x.evaluate... was returning the mocker result values everything became > clearer.) > > To finish my explanation if anyone is still reading: > Then when m.evaluate({}) is called, the x.evaluate(bindings) loads the > mocker.result values to replace the mock objects with the mocker.result > numbers. It works like a normal list comprehension: > The first time thru the list comprehension x = p1. Since the test code for > p1.evaluate({}) is 97.43, it puts 97.43 as the first item in vals list. It > then does the same for p2. So vals = [97.43, -16.25] > > Maybe I am spending too much time on a not so great example, because I see > how the test works, but if I try and use the multiply class normally, and > don't pass it mock objects as the operands (ie pass it numbers), then I get > an attribute error that saying the object has no attribute 'evaluate'. > > the test code looks like this: > from mocker import Mocker > mocker = Mocker() > p1 = mocker.mock() > p1.evaluate({}) > mocker.result(97.43) > p2 = mocker.mock() > p2.evaluate({}) > mocker.result(-16.25) > mocker.replay() > m = multiply(p1, p2) > round(m.evaluate({}),2) > > (the above code was originally in a docstring, I changed it and added it to > the bottom of my multiply module. it isn't a proper test this way...) > > On Sat, Dec 11, 2010 at 10:38 PM, Jeff Hinrichs - DM&T > wrote: > >> You are correct. It's a list comprehension. >> L=[1,2,3] >> print [str(x) for x in L] >> >> Prints out >> ['1', '2','3'] >> >> Jeff >> On Dec 11, 2010 5:19 PM, "Steve Young" wrote: >> > I am going thru a book on testing, and ran across the following code: >> > >> > class multiply: >> > def __init__(self, *operands): >> > self.operands = operands >> > >> > def evaluate(self, bindings): >> > vals = [x.evaluate(bindings) for x in self.operands] >> > >> > if len(vals) < 2: >> > raise ValueError('multiply without at least two ' >> > 'operands is meaningless') >> > >> > result = 1.0 >> > for val in vals: >> > result *= val >> > >> > return result >> > >> > The line " vals = [x.evaluate(bindings) for x in self.operands]" >> > appears to take operand(s) and put them into a list. I can't get my brain >> > to understand it. operands are any number of floating point numbers. Any >> > tips greatly appreciated. >> > >> > >> > -- >> > Steve Young >> > _______________________________________________ >> > Omaha Python Users Group mailing list >> > Omaha at python.org >> > http://mail.python.org/mailman/listinfo/omaha >> > http://www.OmahaPython.org >> _______________________________________________ >> Omaha Python Users Group mailing list >> Omaha at python.org >> http://mail.python.org/mailman/listinfo/omaha >> http://www.OmahaPython.org >> > > > > -- > Steve Young > _______________________________________________ > Omaha Python Users Group mailing list > Omaha at python.org > http://mail.python.org/mailman/listinfo/omaha > http://www.OmahaPython.org From wereapwhatwesow at gmail.com Sun Dec 12 07:08:45 2010 From: wereapwhatwesow at gmail.com (Steve Young) Date: Sun, 12 Dec 2010 00:08:45 -0600 Subject: [omaha] expand my understanding... In-Reply-To: References: Message-ID: if you put the two attachments in a folder, and open a command prompt at that folder, and run: $ python -m doctest tfa1.txt -v you will see all the tests run and pass. (Might need python 2.6 or 2.7.) My problem now is if I wanted to use the multiply class outside of the tests, how would I pass the operands to it so it doesn't give an attribute error. Again, at this point I am beginning to think this was an example of showing how to use mock, not a real life example to try and use, so don't spend a lot of time unless you want to! It is already too late for me...[?] On Sat, Dec 11, 2010 at 11:53 PM, Jeff Hinrichs - DM&T wrote: > Can you paste the code at the problem? > On Dec 11, 2010 11:43 PM, "Steve Young" wrote: > > Thanks Jeff. Good to hear from you, haven't seen you in awhile. > > > > I just figured out that the way the test was running, the operands were > mock > > objects. So when m is instantiated with > > m = multiply(p1, p2) > > self.operands becomes a tuple containing two mock objects. (I originally > > thought it was a tuple containing the numbers, and x.evaluate(bindings) > was > > doing some recursive wierdness with the evaluate function. Once I > realized > > that x.evaluate... was returning the mocker result values everything > became > > clearer.) > > > > To finish my explanation if anyone is still reading: > > Then when m.evaluate({}) is called, the x.evaluate(bindings) loads the > > mocker.result values to replace the mock objects with the mocker.result > > numbers. It works like a normal list comprehension: > > The first time thru the list comprehension x = p1. Since the test code > for > > p1.evaluate({}) is 97.43, it puts 97.43 as the first item in vals list. > It > > then does the same for p2. So vals = [97.43, -16.25] > > > > Maybe I am spending too much time on a not so great example, because I > see > > how the test works, but if I try and use the multiply class normally, and > > don't pass it mock objects as the operands (ie pass it numbers), then I > get > > an attribute error that saying the object has no attribute 'evaluate'. > > > > the test code looks like this: > > from mocker import Mocker > > mocker = Mocker() > > p1 = mocker.mock() > > p1.evaluate({}) > > mocker.result(97.43) > > p2 = mocker.mock() > > p2.evaluate({}) > > mocker.result(-16.25) > > mocker.replay() > > m = multiply(p1, p2) > > round(m.evaluate({}),2) > > > > (the above code was originally in a docstring, I changed it and added it > to > > the bottom of my multiply module. it isn't a proper test this way...) > > > > On Sat, Dec 11, 2010 at 10:38 PM, Jeff Hinrichs - DM&T > > wrote: > > > >> You are correct. It's a list comprehension. > >> L=[1,2,3] > >> print [str(x) for x in L] > >> > >> Prints out > >> ['1', '2','3'] > >> > >> Jeff > >> On Dec 11, 2010 5:19 PM, "Steve Young" > wrote: > >> > I am going thru a book on testing, and ran across the following code: > >> > > >> > class multiply: > >> > def __init__(self, *operands): > >> > self.operands = operands > >> > > >> > def evaluate(self, bindings): > >> > vals = [x.evaluate(bindings) for x in self.operands] > >> > > >> > if len(vals) < 2: > >> > raise ValueError('multiply without at least two ' > >> > 'operands is meaningless') > >> > > >> > result = 1.0 > >> > for val in vals: > >> > result *= val > >> > > >> > return result > >> > > >> > The line " vals = [x.evaluate(bindings) for x in self.operands]" > >> > appears to take operand(s) and put them into a list. I can't get my > brain > >> > to understand it. operands are any number of floating point numbers. > Any > >> > tips greatly appreciated. > >> > > >> > > >> > -- > >> > Steve Young > >> > _______________________________________________ > >> > Omaha Python Users Group mailing list > >> > Omaha at python.org > >> > http://mail.python.org/mailman/listinfo/omaha > >> > http://www.OmahaPython.org > >> _______________________________________________ > >> Omaha Python Users Group mailing list > >> Omaha at python.org > >> http://mail.python.org/mailman/listinfo/omaha > >> http://www.OmahaPython.org > >> > > > > > > > > -- > > Steve Young > > _______________________________________________ > > Omaha Python Users Group mailing list > > Omaha at python.org > > http://mail.python.org/mailman/listinfo/omaha > > http://www.OmahaPython.org > _______________________________________________ > Omaha Python Users Group mailing list > Omaha at python.org > http://mail.python.org/mailman/listinfo/omaha > http://www.OmahaPython.org > -- Steve Young -------------- next part -------------- A non-text attachment was scrubbed... Name: 324.gif Type: image/gif Size: 98 bytes Desc: not available URL: -------------- next part -------------- >>> from mocker import Mocker >>> import operations We're going to test out the constructor for the multiply operation, first. Since all that the constructor has to do is record all of the operands, this is straightforward. >>> mocker = Mocker() >>> p1 = mocker.mock() >>> p2 = mocker.mock() >>> mocker.replay() >>> m = operations.multiply(p1, p2) >>> m.operands == (p1, p2) True >>> mocker.restore() >>> mocker.verify() Now we're going to check the evaluate method for the multiply operation. It should raise a ValueError if there are less than two operands, it should call the evaluate methods of all operations that are operands of the multiply, and of course it should return the correct value. >>> mocker = Mocker() >>> p1 = mocker.mock() >>> p1.evaluate({}) #doctest: +ELLIPSIS >>> mocker.result(97.43) >>> mocker.replay() >>> m = operations.multiply(p1) >>> m.evaluate({}) Traceback (most recent call last): ValueError: multiply without at least two operands is meaningless >>> mocker.restore() >>> mocker.verify() >>> mocker = Mocker() >>> p1 = mocker.mock() >>> p1.evaluate({}) #doctest: +ELLIPSIS >>> mocker.result(97.43) >>> p2 = mocker.mock() >>> p2.evaluate({}) #doctest: +ELLIPSIS >>> mocker.result(-16.25) >>> mocker.replay() >>> m = operations.multiply(p1, p2) >>> round(m.evaluate({}), 2) -1583.24 >>> mocker.restore() >>> mocker.verify() -------------- next part -------------- A non-text attachment was scrubbed... Name: operations.py Type: application/octet-stream Size: 428 bytes Desc: not available URL: From jeffh at dundeemt.com Tue Dec 14 17:34:01 2010 From: jeffh at dundeemt.com (Jeff Hinrichs - DM&T) Date: Tue, 14 Dec 2010 10:34:01 -0600 Subject: [omaha] December meeting In-Reply-To: References: Message-ID: Since there hasn't been any other feedback on the list about the 20th, I'm guessing that attendance will probably be low. How about we just cancel the meeting and start back up in January? Best, Jeff On Mon, Dec 6, 2010 at 2:59 PM, Steve Young wrote: > 1. This is a little early, but our next meeting is on the 20th, the week > of Christmas. I will be out of town that week and wanted to check > everyone's schedules. (No pressure, but I could do next Monday, the 13th > if > anyone is interested.) > 2. I have just finished the Python Koans!! It was a good learning > experience, and picked up a few good tools along the way. > 3. I am still trying to get a weekly lunch meetup going: > 1. Who is interested? > 2. Where to meet? > 3. What to do? > 4. Maybe start after the holidays? > > > -- > --Steve Young > _______________________________________________ > Omaha Python Users Group mailing list > Omaha at python.org > http://mail.python.org/mailman/listinfo/omaha > http://www.OmahaPython.org > -- Jeff Hinrichs Dundee Media & Technology, Inc jeffh at dundeemt.com 402.218.1473 web: www.dundeemt.com blog: inre.dundeemt.com From wereapwhatwesow at gmail.com Tue Dec 14 20:50:03 2010 From: wereapwhatwesow at gmail.com (Steve Young) Date: Tue, 14 Dec 2010 13:50:03 -0600 Subject: [omaha] December meeting In-Reply-To: References: Message-ID: Sounds like a good idea. I will call and cancel the reservation. Merry Christmas to everyone! On Tue, Dec 14, 2010 at 10:34 AM, Jeff Hinrichs - DM&T wrote: > Since there hasn't been any other feedback on the list about the 20th, I'm > guessing that attendance will probably be low. How about we just cancel > the > meeting and start back up in January? > > Best, > > Jeff > > On Mon, Dec 6, 2010 at 2:59 PM, Steve Young >wrote: > > > 1. This is a little early, but our next meeting is on the 20th, the > week > > of Christmas. I will be out of town that week and wanted to check > > everyone's schedules. (No pressure, but I could do next Monday, the > 13th > > if > > anyone is interested.) > > 2. I have just finished the Python Koans!! It was a good learning > > experience, and picked up a few good tools along the way. > > 3. I am still trying to get a weekly lunch meetup going: > > 1. Who is interested? > > 2. Where to meet? > > 3. What to do? > > 4. Maybe start after the holidays? > > > > > > -- > > --Steve Young > > _______________________________________________ > > Omaha Python Users Group mailing list > > Omaha at python.org > > http://mail.python.org/mailman/listinfo/omaha > > http://www.OmahaPython.org > > > > > > -- > Jeff Hinrichs > Dundee Media & Technology, Inc > jeffh at dundeemt.com > 402.218.1473 > web: www.dundeemt.com > blog: inre.dundeemt.com > _______________________________________________ > Omaha Python Users Group mailing list > Omaha at python.org > http://mail.python.org/mailman/listinfo/omaha > http://www.OmahaPython.org > -- Steve Young From choman at gmail.com Fri Dec 17 19:20:04 2010 From: choman at gmail.com (Chad Homan) Date: Fri, 17 Dec 2010 12:20:04 -0600 Subject: [omaha] [OT] Delicious Users Get, your marks now Message-ID: Just saw this, but yahoo is axing 8 web services including delicious http://www.betanews.com/article/Yahoo-to-terminate-8-web-properties-in-restructuring-effort/1292566062 Chad, CISSP From choman at gmail.com Thu Dec 23 23:51:15 2010 From: choman at gmail.com (Chad Homan) Date: Thu, 23 Dec 2010 16:51:15 -0600 Subject: [omaha] Happy Holidays Message-ID: Wishing everyone a safe and exciting holiday season Merry Xmas and Happy New Year See everyone in 2011 Chad, CISSP