def setUpClass(self): Logger.pushLogData("unitTesting", __name__) forceWorkingDirectory() pyswing.globals.potentialRuleMatches = None pyswing.globals.equityCount = None pyswing.database.overrideDatabase("output/TestDatabase.db") pyswing.constants.pySwingStartDate = datetime.datetime(2015, 1, 1) deleteFile(pyswing.database.pySwingDatabase) deleteFile(pyswing.database.pySwingTestDatabase) args = "-n %s" % ("unitTesting") createDatabase(args.split()) pretendDate = datetime.datetime(2015, 7, 1) with patch.object(Equity, '_getTodaysDate', return_value=pretendDate) as mock_method: args = "-n unitTest".split() importData(args) args = "-n unitTest".split() updateIndicators(args) args = "-n unitTest".split() evaluateRules(args) args = "-n unitTest".split() analyseRules(args) args = "-n unitTest".split() calculateExitValues(args)
def test_CalculateExitValues(self): pretendDate = datetime.datetime(2015, 6, 1) with patch.object(Equity, '_getTodaysDate', return_value=pretendDate) as mock_method: args = "-n unitTest".split() importData(args) args = "-n unitTest".split() calculateExitValues(args) rowCount = self._countRows("Exit TrailingStop3.0 RiskRatio2") self.assertEqual(rowCount, 606)
def test_UpdateIndicators(self): pretendDate = datetime.datetime(2015, 6, 1) with patch.object(Equity, '_getTodaysDate', return_value=pretendDate) as mock_method: args = "-n unitTest".split() importData(args) args = "-n unitTest".split() updateIndicators(args) rowCount = self._countRows("Indicator_SMA") anotherRowCount = self._countRows("Indicator_ROC") self.assertEqual(rowCount, 321) self.assertEqual(rowCount, anotherRowCount)
def test_ImportData(self): pretendDate = datetime.datetime(2015, 5, 1) with patch.object(Equity, '_getTodaysDate', return_value=pretendDate) as mock_method: args = "-n unitTest".split() importData(args) rowCount = self._countEquityRows() self.assertEqual(rowCount, 261) # 87 * 3 pretendDate = datetime.datetime(2015, 6, 1) with patch.object(Equity, '_getTodaysDate', return_value=pretendDate) as mock_method: args = "-n unitTest".split() importData(args) rowCount = self._countEquityRows() self.assertEqual(rowCount, 324) # 108 * 3
def test_EvaluateRules(self): pretendDate = datetime.datetime(2015, 7, 1) with patch.object(Equity, '_getTodaysDate', return_value=pretendDate) as mock_method: args = "-n unitTest".split() importData(args) args = "-n unitTest".split() updateIndicators(args) args = "-n unitTest".split() evaluateRules(args) rowCount = self._countRows("Rule Indicator_STOCH STOCH_K < 5") anotherRowCount = self._countRows("Rule Indicator_RSI RSI > 20") self.assertEqual(rowCount, 387) self.assertEqual(rowCount, anotherRowCount)
def test_AnalyseRules(self): pretendDate = datetime.datetime(2015, 7, 1) with patch.object(Equity, '_getTodaysDate', return_value=pretendDate) as mock_method: args = "-n unitTest".split() importData(args) args = "-n unitTest".split() updateIndicators(args) args = "-n unitTest".split() evaluateRules(args) args = "-n unitTest".split() analyseRules(args) rowCount = self._countRows("Rules") self.assertEqual(rowCount, 182)