Home Download Buy Blog Forum Support

Unit Testing Plugins?

Unit Testing Plugins?

Postby virtix on Tue Jan 03, 2012 1:06 am

New user here. Just wrote my first plugin (fun API!); but I'm having an issue writing tests for the plugin. It could be a simple Python issue, too (I'm relatively new to Python, as well). This is the error:

Code: Select all
ImportError: No module named sublime


Here's the distilled unit test, which resides in my-plugin/tests:

Code: Select all
import unittest
import json
from my_plugin import MyCommand

class MyUnitTest(unittest.TestCase):
   
   def test_read_json_data(self):
       ...


Very abbreviated plugin:

Code: Select all
import sublime_plugin
import sublime

class MyCommand(sublime_plugin.TextCommand):
    def run(edit):
    ...


It fails on the 'import sublime' statement above when I try to instantiate 'MyCommand'. In other words, the test code doesn't execute beyond the import statements.

So, where is the sublime module such that I can add it to my path? Or maybe there's a different (better?) approach to writing tests?

Any help is much appreciated!

-bill
virtix
 
Posts: 4
Joined: Tue Jan 03, 2012 12:44 am
Location: DC, US

Re: Unit Testing Plugins?

Postby C0D312 on Tue Jan 03, 2012 1:28 am

This might help for making your plugin: http://sublimetext.info/docs/en/reference/plugins.html

Why I don't know much about unit testing, I might be about to help with the plugin. Could I ask what you're trying to do?
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Unit Testing Plugins?

Postby virtix on Tue Jan 03, 2012 1:43 am

Thanks. I've built a working plugin with a handful of commands, keyboard shortcuts, etc; but I can't figure out how to write even basic unit tests for it, which is how I'm used to building software (ala TDD).

C0D312 wrote: Could I ask what you're trying to do?

I'm building unit test runner plugins.

-bill
virtix
 
Posts: 4
Joined: Tue Jan 03, 2012 12:44 am
Location: DC, US

Re: Unit Testing Plugins?

Postby quarnster on Tue Jan 03, 2012 9:25 am

Are you trying to run the unit test with your system's python? The sublime module doesn't exist outside of the application, so you need to run your python code with the built in interpreter.
quarnster
 
Posts: 389
Joined: Tue Nov 29, 2011 11:34 am

Re: Unit Testing Plugins?

Postby virtix on Tue Jan 03, 2012 11:41 am

quarnster wrote:Are you trying to run the unit test with your system's python? The sublime module doesn't exist outside of the application, so you need to run your python code with the built in interpreter.


Ah, now it's starting to make sense--thanks! I'm using nose as the runner, which uses my system's python. So, the built-in interpreter is lib/python26 ?

-bill
virtix
 
Posts: 4
Joined: Tue Jan 03, 2012 12:44 am
Location: DC, US

Re: Unit Testing Plugins?

Postby guillermooo on Tue Jan 03, 2012 10:49 pm

I've found an approach that seems to work acceptably for testing plugins:

https://github.com/SublimeText/VintageE ... ster/tests

There's more testing-related code in here:

https://github.com/SublimeText/VintageE ... _runner.py

It still needs some work, though.
guillermooo
 
Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

Re: Unit Testing Plugins?

Postby virtix on Fri Jan 06, 2012 12:12 pm

Thanks, guillermoo. That looks interesting. Stupid question: how do you "run" the tests?

bill
virtix
 
Posts: 4
Joined: Tue Jan 03, 2012 12:44 am
Location: DC, US

Re: Unit Testing Plugins?

Postby guillermooo on Fri Jan 06, 2012 12:38 pm

You need to run them manually by running "vintage_ex_test_runner_commander" (which needs a better name :). I might have restricted some of the necessary commands to run only if the current directory is pointing to the "VintageEx" package. I did this so I wouldn't be able to accidentally run the tests when I'm not developing "VintageEx". I put all of this together quite quickly without too much thinking, so I'll have to make some changes to the code.
guillermooo
 
Posts: 729
Joined: Thu Jul 23, 2009 9:06 am


Return to Plugin Development

Who is online

Users browsing this forum: v0rtex and 5 guests

cron