From c4cfa752322df4b1c8456445e5536685d3160f9a Mon Sep 17 00:00:00 2001 From: Sudarshan Sathe Date: Wed, 17 Apr 2019 11:46:53 +0530 Subject: [PATCH] Fix : python path + uni test + added Test resourses --- GingerPythonPluginConsole/PythonProcess.cs | 2 +- .../GingerPythonPluginTest.csproj | 8 ++++- GingerPythonPluginTest/TestAssemblyInit.cs | 20 +++++++++++ .../TestResources/sum-file.py | 7 ++++ GingerPythonPluginTest/UnitTest1.cs | 36 ++++++++++--------- 5 files changed, 54 insertions(+), 19 deletions(-) create mode 100644 GingerPythonPluginTest/TestAssemblyInit.cs create mode 100644 GingerPythonPluginTest/TestResources/sum-file.py diff --git a/GingerPythonPluginConsole/PythonProcess.cs b/GingerPythonPluginConsole/PythonProcess.cs index 0fa5a3c..5083a68 100644 --- a/GingerPythonPluginConsole/PythonProcess.cs +++ b/GingerPythonPluginConsole/PythonProcess.cs @@ -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"; } diff --git a/GingerPythonPluginTest/GingerPythonPluginTest.csproj b/GingerPythonPluginTest/GingerPythonPluginTest.csproj index 8175df9..549b8d1 100644 --- a/GingerPythonPluginTest/GingerPythonPluginTest.csproj +++ b/GingerPythonPluginTest/GingerPythonPluginTest.csproj @@ -5,7 +5,7 @@ false - true + false @@ -19,4 +19,10 @@ + + + PreserveNewest + + + diff --git a/GingerPythonPluginTest/TestAssemblyInit.cs b/GingerPythonPluginTest/TestAssemblyInit.cs new file mode 100644 index 0000000..b617ef3 --- /dev/null +++ b/GingerPythonPluginTest/TestAssemblyInit.cs @@ -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(); + } + } +} diff --git a/GingerPythonPluginTest/TestResources/sum-file.py b/GingerPythonPluginTest/TestResources/sum-file.py new file mode 100644 index 0000000..1560f79 --- /dev/null +++ b/GingerPythonPluginTest/TestResources/sum-file.py @@ -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)) \ No newline at end of file diff --git a/GingerPythonPluginTest/UnitTest1.cs b/GingerPythonPluginTest/UnitTest1.cs index 1a6a1f9..d4b3d99 100644 --- a/GingerPythonPluginTest/UnitTest1.cs +++ b/GingerPythonPluginTest/UnitTest1.cs @@ -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; @@ -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); @@ -49,7 +50,7 @@ public void RunScript2() @"a = 'hello' b = ' world' str = a + b -print 'str=' + 'hello world' +print('str=' + 'hello world') "; //Act @@ -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); @@ -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); @@ -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); @@ -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 args = new List(); args.Add(new Arg("4")); @@ -162,6 +163,7 @@ public void RunScript6() Assert.AreEqual("11", GA.Output["sum"]); } //====================== Script file ================== + [Ignore] [TestMethod] public void RunScript7() { @@ -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