Professional IronPython



Download 20,35 Mb.
Pdf ko'rish
bet336/453
Sana01.07.2022
Hajmi20,35 Mb.
#723045
1   ...   332   333   334   335   336   337   338   339   ...   453
lISTINg 15-6: 
 Accessing IronPython from Visual Basic.NET
Sub Main()
‘ Create an engine to access IronPython.
Dim Eng As ScriptEngine = Python.CreateEngine()
‘ Describe where to load the script.
Dim Source As ScriptSource = Eng.CreateScriptSourceFromFile(“TestClass.py”)
‘ Obtain the default scope for executing the script.
Dim Scope As ScriptScope = Eng.CreateScope()
‘ Create an object for performing tasks with the script.
Dim Ops As ObjectOperations = Eng.CreateOperations()
‘ Create the class object.
Source.Execute(Scope)
‘ Obtain the class object.
Dim CalcClass As Object = Scope.GetVariable(“DoCalculations”)
‘ Create an instance of the class.
Dim CalcObj As Object = Ops.Invoke(CalcClass)
‘ Get the method you want to use from the class instance.
Dim AddMe As Object = Ops.GetMember(CalcObj, “DoAdd”)
‘ Perform the add.
Dim Result As Int32 = Ops.Invoke(AddMe, 5, 10)
‘ Display the result.
Console.WriteLine(“5 + 10 = {0}“, Result)
‘ Pause after running the test.
Console.WriteLine(vbCrLf + “Press any key when ready...”)
Console.ReadKey()
End Sub
As you can see from the listing, Visual Basic.NET code uses precisely the same process as C# does 
to access IronPython scripts. In fact, you should compare this listing to the content of Listing 15-2. 
The two examples are similar so that you can compare them. The output is also precisely the same. 
You’ll see the output shown in Figure 15-3 when you execute this example.
548592c15.indd 320
2/25/10 9:45:56 AM
www.finebook.ir


Debugging the External Module
 

 
321
dEvEloPINg TEST PRoCEdURES FoR ExTERNAl modUlES
Many developers are beginning to realize the benefits of extensive application testing. There are 
entire product categories devoted to the testing process now because testing is so important. Most, if 
not all, developer tools now include some idea of application testing with them. In short, you should 
have all the testing tools you need to test the static portion of your IronPython application.
Unfortunately, the testing tools might not work particularly well with the dynamic portion of the 
application. Creating a test that goes from the static portion of the application to the dynamic por-
tion of the application is hard. (Chapter 18 shows that the opposite isn’t true — IronPython makes 
an excellent tool for testing your static application.) Consequently, you need to include a test harness 
with your dynamic code and perform thorough testing of the dynamic code before you use it with 
the static application. (When you think about a test harness, think about a horse, your application 
that has a harness added externally for testing purposes. You add the harness for testing and remove 
it for production work without modifying the application.) Listing 15-1 shows an example of how 
you might perform this task.
The test harness you create has to test everything, which is a daunting task to say the least. In addi-
tion, you need to expend extra effort to make the test harness error free — nothing would be worse 
than to chase an error through your code, only to find out that the error is in the test harness. At a 
minimum, your test harness should perform the following checks on your dynamic code:

Outputs with good inputs

Outputs with erroneous inputs


Exception handling within methods


Property value handling


Exceptions that occur on public members that would normally be private


Of course, you want to check every method and property of every class within the dynamic code. 
To ensure you actually test everything, make sure you create a checklist to use to verify your test 
harness. Because IronPython isn’t compiled, you’ll find that you must manually perform some 
checks to ensure the code works precisely as planned, but use as much automation as possible.

Download 20,35 Mb.

Do'stlaringiz bilan baham:
1   ...   332   333   334   335   336   337   338   339   ...   453




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish