forked from QuantConnect/Lean
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoaderTests.cs
119 lines (98 loc) · 4.69 KB
/
LoaderTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using NUnit.Framework;
using QuantConnect.AlgorithmFactory;
using QuantConnect.Interfaces;
using System;
using System.Linq;
using QuantConnect.Util;
namespace QuantConnect.Tests.AlgorithmFactory
{
[TestFixture]
public class LoaderTests
{
private WorkerThread _workerThread;
[SetUp]
public void SetUp()
{
_workerThread = new TestWorkerThread();
}
[TearDown]
public void TearDown()
{
_workerThread.Dispose();
}
[Test]
public void LoadsSamePythonAlgorithmTwice()
{
var assemblyPath = "../../../Algorithm.Python/BasicTemplateAlgorithm.py";
string error1;
IAlgorithm algorithm1;
var one = new Loader(false, Language.Python, TimeSpan.FromMinutes(1), names => names.SingleOrDefault(), _workerThread)
.TryCreateAlgorithmInstanceWithIsolator(assemblyPath, 5120, out algorithm1, out error1);
string error2;
IAlgorithm algorithm2;
var two = new Loader(false, Language.Python, TimeSpan.FromMinutes(1), names => names.SingleOrDefault(), _workerThread)
.TryCreateAlgorithmInstanceWithIsolator(assemblyPath, 5120, out algorithm2, out error2);
Assert.AreNotEqual(algorithm1.ToString(), algorithm2.ToString());
}
[Test]
public void LoadsTwoDifferentPythonAlgorithm()
{
var assemblyPath1 = "../../../Algorithm.Python/BasicTemplateAlgorithm.py";
var assemblyPath2 = "../../../Algorithm.Python/AddRemoveSecurityRegressionAlgorithm.py";
string error1;
IAlgorithm algorithm1;
var one = new Loader(false, Language.Python, TimeSpan.FromMinutes(1), names => names.SingleOrDefault(), _workerThread)
.TryCreateAlgorithmInstanceWithIsolator(assemblyPath1, 5120, out algorithm1, out error1);
string error2;
IAlgorithm algorithm2;
var two = new Loader(false, Language.Python, TimeSpan.FromMinutes(1), names => names.SingleOrDefault(), _workerThread)
.TryCreateAlgorithmInstanceWithIsolator(assemblyPath2, 5120, out algorithm2, out error2);
Assert.AreNotEqual(algorithm1.ToString(), algorithm2.ToString());
}
[Test]
[TestCase("BasicTemplateAlgorithm")]
[TestCase("QuantConnect.Algorithm.CSharp.BasicTemplateAlgorithm")]
public void LoadsAlgorithm_UsingSingleOrAlgorithmTypeName_ExtensionMethod(string algorithmName)
{
var assemblyPath1 = "QuantConnect.Algorithm.CSharp.dll";
string error1;
IAlgorithm algorithm1;
var one = new Loader(false, Language.CSharp, TimeSpan.FromMinutes(1), names => names.SingleOrAlgorithmTypeName(algorithmName), _workerThread)
.TryCreateAlgorithmInstanceWithIsolator(assemblyPath1, 5120, out algorithm1, out error1);
Assert.IsTrue(one);
}
[Test]
public void LoadsSepereateAlgorithm_UsingSingleOrAlgorithmTypeName_ExtensionMethod()
{
var assemblyPath = "QuantConnect.Algorithm.CSharp.dll";
string error1;
IAlgorithm algorithm1;
var one = new Loader(false, Language.CSharp, TimeSpan.FromMinutes(1), names => names.SingleOrAlgorithmTypeName("BasicTemplateAlgorithm"), _workerThread)
.TryCreateAlgorithmInstanceWithIsolator(assemblyPath, 5120, out algorithm1, out error1);
string error2;
IAlgorithm algorithm2;
var two = new Loader(false, Language.CSharp, TimeSpan.FromMinutes(1), names => names.SingleOrAlgorithmTypeName("BasicTemplateForexAlgorithm"), _workerThread)
.TryCreateAlgorithmInstanceWithIsolator(assemblyPath, 5120, out algorithm2, out error2);
Assert.IsTrue(one);
Assert.IsTrue(two);
Assert.AreNotEqual(algorithm1.ToString(), algorithm2.ToString());
}
private class TestWorkerThread : WorkerThread
{
}
}
}