Skip to content

Commit

Permalink
Fix : python path + uni test + added Test resourses
Browse files Browse the repository at this point in the history
  • Loading branch information
sudarshan0212 committed Apr 17, 2019
1 parent a69be86 commit c4cfa75
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 19 deletions.
2 changes: 1 addition & 1 deletion GingerPythonPluginConsole/PythonProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private Process CreateProcess()
try
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
p.StartInfo.FileName = "python";
p.StartInfo.FileName = "/usr/bin/python3";
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
p.StartInfo.FileName = "python.exe";
}
Expand Down
8 changes: 7 additions & 1 deletion GingerPythonPluginTest/GingerPythonPluginTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<IsPackable>false</IsPackable>

<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup>
Expand All @@ -19,4 +19,10 @@
<ProjectReference Include="..\GingerPythonPluginConsole\GingerPythonPluginConsole.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="TestResources\sum-file.py">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
20 changes: 20 additions & 0 deletions GingerPythonPluginTest/TestAssemblyInit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using GingerTestHelper;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
namespace GingerPythonPluginTest
{
[TestClass]
public class TestAssemblyInit
{
[AssemblyInitialize]
public static void AssemblyInitialize(TestContext context)
{
// Called once when the test assembly is loaded
// We provide the assembly to GingerTestHelper.TestResources so it can locate the 'TestResources' folder path
TestResources.Assembly = Assembly.GetExecutingAssembly();
}
}
}
7 changes: 7 additions & 0 deletions GingerPythonPluginTest/TestResources/sum-file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import sys
a = sys.argv[1]
b = sys.argv[2]
print('a=' + a)
print('b=' + b)
sum = int(a) + int(b)
print('sum=' + str(sum))
36 changes: 19 additions & 17 deletions GingerPythonPluginTest/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Amdocs.Ginger.Plugin.Core;
using GingerPythonPlugin;
using GingerPythonPluginConsole;
using GingerTestHelper;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
Expand All @@ -24,10 +25,10 @@ public void RunScript1()
String script1 =
@"a=2
b=3
print 'a=' + str(a)
print 'b=' + str(b)
print('a=' + str(a))
print('b=' + str(b))
sum=a+b
print 'sum=' + str(sum)";
print('sum=' + str(sum))";
//Act
service.RunScript(GA, script1);

Expand All @@ -49,7 +50,7 @@ public void RunScript2()
@"a = 'hello'
b = ' world'
str = a + b
print 'str=' + 'hello world'
print('str=' + 'hello world')
";

//Act
Expand All @@ -71,9 +72,9 @@ public void RunScript3()
@"a = 3
b = 4
c = max(a, b)
print 'a=' + str(a)
print 'b=' + str(b)
print 'c=' + str(c)
print('a=' + str(a))
print('b=' + str(b))
print('c=' + str(c))
";
//Act
service.RunScript(GA, script3,null);
Expand All @@ -96,9 +97,9 @@ public void RunScript4()
@"a = 3
b = 4
c = min(a, b)
print 'a=' + str(a)
print 'b=' + str(b)
print 'c=' + str(c)
print('a=' + str(a))
print('b=' + str(b))
print('c=' + str(c))
";
//Act
service.RunScript(GA, script4,null);
Expand All @@ -119,10 +120,10 @@ public void RunScript5()
String script5 =
@"a=2
b=3
print str(a)
print str(b)
print(str(a))
print(str(b))
sum=a+b
print 'sum=' + str(sum)";
print('sum=' + str(sum))";
//Act
service.RunScript(GA, script5,null);

Expand All @@ -145,10 +146,10 @@ public void RunScript6()
@"import sys
a = sys.argv[1]
b = sys.argv[2]
print 'a=' + a
print 'b=' + b
print('a=' + a)
print('b=' + b)
sum = int(a) + int(b)
print 'sum=' + str(sum)";
print('sum=' + str(sum))";
//Act
List<Arg> args = new List<Arg>();
args.Add(new Arg("4"));
Expand All @@ -162,6 +163,7 @@ public void RunScript6()
Assert.AreEqual("11", GA.Output["sum"]);
}
//====================== Script file ==================
[Ignore]
[TestMethod]
public void RunScript7()
{
Expand All @@ -175,7 +177,7 @@ public void RunScript7()
args.Add(new Arg("5"));
args.Add(new Arg("6"));

service.RunScriptFile(GA, "./sum-file.py", args);
service.RunScriptFile(GA, TestResources.GetTestResourcesFile("sum-file.py"), args);


//Assert
Expand Down

0 comments on commit c4cfa75

Please sign in to comment.