This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Generating tests on the fly | |
import unittest | |
class CheckIntTest(object): | |
def test_isIntReturned(self): | |
print "Calling test method with 2, 3" | |
print "Test method result %s"%(self.calc(2,3)) | |
self.assertIsInstance(self.calc(2,3),int) | |
def m1(self,a,b): | |
return a+b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="group"> | |
<input type="text" required> | |
<span class="highlight"></span> | |
<span class="bar"></span> | |
<label>Email</label> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mock | |
class Patchee(object): | |
def name(self): | |
return "Patchee" | |
class MyContextPatcher(object): | |
def __init__(self, newName): | |
self.newName = newName | |
def __enter__(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import partial | |
def power(number, order): | |
"""This is a power function""" | |
return number ** order | |
square = partial( power, order = 2) | |
cube = partial( power, order = 3) | |
if __name__ == "__main__": |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Thirty360DayCountCalculator( DayCountCalculator ): | |
""" | |
A month is considered of 30 days and a year is of 360 days. | |
ISDA recommended method for day count is | |
360(y2-y1)+30(m2-m1-1)+max(0,30-d1)+min(30,d2) | |
* Take year diff | |
* Take month diff + 1 month to be adjusted by date | |
* Since every month is 30 and reduce d1 from it, and take | |
max with 0 in case result is negative ( days to 30 ) | |
* days in d2, min if more than 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Date | Dirty Price | |
---|---|---|
2010-01-06 | 70.8441666667 | |
2010-01-26 | 72.5102777778 | |
2010-02-05 | 72.8090277778 | |
2010-02-15 | 72.0220833333 | |
2010-02-25 | 73.0951388889 | |
2010-03-17 | 73.9898611111 | |
2010-04-06 | 74.4316666667 | |
2010-04-16 | 74.8647222222 | |
2010-04-26 | 75.1277777778 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def decorator(func): | |
""" | |
:param func: | |
:return: func result after calling it with 1 | |
""" | |
return func(1) | |
#Below statement is equal to decorator( decoratee ) | |
@decorator | |
def decoratee(number): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@memoize | |
def add_values( a, b ): | |
return a+b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyOtherProperty(object): | |
def __init__(self, name): | |
self.name = name | |
def getXName(self): | |
return self.name | |
def setXName(self, val): | |
self.name = val |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyFinalProperty(object): | |
@property | |
def name(self): | |
return "John" |
NewerOlder