how to understand/convert a foreign addon (<= 2.49)of several files?! Use UNITTESTS!


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 :smiley:


The Borgs have tested a new ‘drive’ (to escape quickly)

http://www.petergragert.info/pmwiki/uploads/Animation/borg_0.gif

I will make a zip to download … and the link will come soon after permission of Keines :wink:

It was GPL so no answer is needed from Keines :evilgrin:

Here it is:
http://dl.dropbox.com/u/8767830/Astro020112.zip

Get it and unpack into 2.61/scripts/addons (should create Astro!)

addon is then to be found mesh => Astro (or search for Astro at once)

A panel will be in the toolshelf!

To see my latest unittest working do the follwoing:
In Blender open ‘Scripting’ ==> click Text ==> Alt O and Alt P to run (or what you like differently to activate :stuck_out_tongue: )

You will get

ERROR: test_helpText (main.astro_Test)

Traceback (most recent call last):
File “\unit_3_astro.py”, line 72, in test_helpText
AttributeError: ‘module’ object has no attribute ‘helpText’

Because I implemented the Help differently and the test was not removed!

Therefor open unit_3_astro.py in your (favorite) text-editor and remove the test or …
save
Blender will see the change, so you can reload it in Blender (one click!) and run again …

Exercise: Make a Blackhole (easyly!) by adding e.g. a cube in edit mode of some stars mesh
(in the view area) and see what happens ==> Black Hole! Move it! :evilgrin:

Strange, depending On PC one will get error ??!! not at home with fresh Blender and only Execute (no change of parameters)
please tell (here) PM or so

Eventually make this small change(addition!)
In Astro261.py change Line
rexp=re.compile("[^
]+") into rexp=re.compile("[^
]+")

See the space after the ^ …! line around 875

Maybe in the zip AstroDeg.dat does not contain tab as separate the data??


Why is Dubhe ‘green’?

THIS is done by very simple changes!
Get the RA (right accension) Dec (declination) of a star you are interested in!
Compute the decimal values
Fill it in into AstroDeg.dat (second e.g. line)
RA tab DEC tab -2 tab A nl

There are in the original NO stars with -2 so a mesh with -2 in the name will be created
with only ONE vertex YOUR Star in it!
Execute the addon!
Give it a different colour!

Hallo, just updated the *.zip …
One error removed, and the text of starsystems is nicely seen at once (help is not up to date I see) …

Who tries this addon? Please tell here if it works or give the error message.

EDIT: the main script: repaired Atro261.py is now back again :wink:

EDIT EDIT 8 jan 11:12 Help adjusted and star-text should be aligned to camera view

Move a default cube away (or delete it) from the origin, there the camera will be set!

Small error found and removed … *.zip is updated.

The error was, if stars are removed in one session new star-object got name .star[…].000 (or so) … this is now dealt with :wink:

Hallo, and now busy with stars in the starssytesm:
“Proefkonijn” = Pegasus!

And as an animation OF ONLY PEGASUS stars (new feature!)
http://www.petergragert.info/pmwiki/uploads/Animation/Pegasus.gif