
I am just busy to convert Astro to >= 2.61 from <=2.49
There are 4 files to tackle!
The boss, two helpers and one data file!
How did I do this? So:
step 1: Created in */addons the directory Astro
step 2: putted the 4 files into the new Astro
step 3: make a init.py (with addons stuff, see other examples); have at least ONE class in the ‘boss’ , addons need a class!
step 4: change and add as much as you can see directly …in the sources.
STEP5: prepare your unittest.py file!!! (see below)
Step 6: Load the unittest files as a text in Blender and open it in your favorite TEXT-editor, you will probably have to edit it in the beginning frequently, SAVE it after a change and in Blender you ONLY have to click the (red) Button which occurs after as save!
Step 7: run your tests and inspect the outcome! ==> adjust source (or unittest) as needed.
Now a very important ‘thing’: changing the real source files forced me to quit blender and to start again to see the change in the source BUT that can and should/MUST be avoided, it costs too much boring quit and execute Blender!
Step 8: adjust your unittest file with respect to the foregoing sentence!!! Done you adjust your source (in your favorite …) save and you can at once rerun your tests!!!
I will show now parts of the unit test file, such that you get an idea!
My is called ‘unit_astro.py’ :D.
Top:
import unittest
import bpy
from mathutils import Vector #needed to check vertex.vector values
print("
---------- test-- pkhg astro-----------
")
You need a Test class and I use a setup too (better to have!)
name ****_TEST(unittest.TestCase):
class astro_Test(unittest.TestCase):
def setUp(self): #FOR THREE REAL SOURCEFILES!
self.Astro261_module = None
self.AstroU = None
self.AstroD = None
try:
#PKHG to run several times register unregister needed
if "bpy" in locals():
import imp
imp.reload(Astro261)
self.Astro261_module = Astro261
print("!!!!!!!! self.Astro =
",self.Astro)
else:
from Astro import Astro261
from Astro import AstroUnit
from Astro import AstroDat
# print("Astro261 = ", Astro261)
self.Astro261_module = Astro261
self.AstroU = AstroUnit
self.AstroD = AstroDat
# print("
-----------------")
# print(dir(Astro261_module))
# print("
-----------------")
#'''
except:
print("error???")
finally:
pass
Yous see several comments … inserted after being content, but you never know …!
Next (at the bottom) you have to activate the Test (clicking run file (=execute) of the text in Blender)
########activate the test
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(astro_Test)
# unittest.TextTestRunner(verbosity=3).run(suite)
unittest.TextTestRunner(verbosity=1).run(suite) #one gives points for OK tests
And in between your REAL test(s!), where I show you how to prevent quitting and restarting Blender
def test_Astro_make(self):
import imp
imp.reload(self.Astro261_module)
imp.reload(self.AstroU)
Astro261_module = self.Astro261_module
self.Astro261_module.NowDate(0,6)
file = "c:/BlenderSVN/cmake_all3/bin/2.61/scripts/addons/Astro/AstroDeg.dat"
import os
self.assertTrue(os.path.isfile(file))
self.assertTrue(Astro261_module.BtnList_Longitude)
# self.assertTrue(Astro261_module.BtnList[Astro261_module.BtnList_Longitude][2])
#OK print("ASTR BtnList",Astro261_module.BtnList)
longitude = Astro261_module.BtnList[Astro261_module.BtnList_Longitude][2]
print("longitude = ============",longitude)
latitude = Astro261_module.BtnList[Astro261_module.BtnList_Latitude][2]
BaseTime = [Astro261_module.BtnList[i][2] for i in range(6)]
Astro261_module.AstroMake(file, BaseTime, longitude,latitude)
THE important thing is: the import imp and the lines following the imp.reload(…)!
THAT works by me Blender 2.61 W32 Vista.
By the way, self.assertTrue is the unittest test
Sometimes it is preferable to use
try, except, finally,
but that depends is is up to you.
Slowly saw the needed changes from 2.49 to >= 2.61
Ask if you have questions 



)

