<div dir="ltr"><div>Dear all.</div><div><br></div><div>I want make a QGIS Python plugin with unit test using the 'Plugin Builder'</div><div>The 'Plugin Builder' make some unit test class automatically in test folder like as test_init.py,  test_translations.py.</div>
<div>I want to do unit test by these class but I had failed.</div><div><br></div><div>This is my unit test code.</div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<font face="courier new, monospace">import unittest<br></font><font face="courier new, monospace">import MyPlugin<br></font><font face="courier new, monospace">from MyPlugin.test.test_init import TestInit</font><font face="courier new, monospace"><br>
</font><font face="courier new, monospace">suite = unittest.TestLoader().loadTestsFromTestCase(TestInit)<br></font><font face="courier new, monospace">unittest.TextTestRunner(verbosity=2).run(suite)</font></blockquote></div>
<div><br></div><div>But, execute results is like this.</div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<font face="courier new, monospace">Traceback (most recent call last):<br>  File "<input>", line 1, in <module><br>  File "C:/Temp/qgisPluginUnitTest.py", line 4, in <module><br>    unittest.TextTestRunner(verbosity=2).run(suite)<br>
  File "C:\PROGRA~1\QGISVA~1\apps\Python27\lib\unittest\runner.py", line 151, in run<br>    test(result)<br>  File "C:\PROGRA~1\QGISVA~1\apps\Python27\lib\unittest\suite.py", line 70, in __call__<br>    return self.run(*args, **kwds)<br>
  File "C:\PROGRA~1\QGISVA~1\apps\Python27\lib\unittest\suite.py", line 108, in run<br>    test(result)<br>  File "C:\PROGRA~1\QGISVA~1\apps\Python27\lib\unittest\case.py", line 395, in __call__<br>    return self.run(*args, **kwds)<br>
  File "C:\PROGRA~1\QGISVA~1\apps\Python27\lib\unittest\case.py", line 306, in run<br>    result.startTest(self)<br>  File "C:\PROGRA~1\QGISVA~1\apps\Python27\lib\unittest\runner.py", line 55, in startTest<br>
    self.stream.flush()<br>IOError: [Errno 9] Bad file descriptor<br>execfile(u'C:/Temp/qgisPluginUnitTest.py'.encode('mbcs'))<br>Traceback (most recent call last):<br>  File "<input>", line 1, in <module><br>
  File "C:/Temp/qgisPluginUnitTest.py", line 5, in <module><br>    unittest.TextTestRunner(verbosity=2).run(suite)<br>  File "C:\PROGRA~1\QGISVA~1\apps\Python27\lib\unittest\runner.py", line 151, in run<br>
    test(result)<br>  File "C:\PROGRA~1\QGISVA~1\apps\Python27\lib\unittest\suite.py", line 70, in __call__<br>    return self.run(*args, **kwds)<br>  File "C:\PROGRA~1\QGISVA~1\apps\Python27\lib\unittest\suite.py", line 108, in run<br>
    test(result)<br>  File "C:\PROGRA~1\QGISVA~1\apps\Python27\lib\unittest\case.py", line 395, in __call__<br>    return self.run(*args, **kwds)<br>  File "C:\PROGRA~1\QGISVA~1\apps\Python27\lib\unittest\case.py", line 306, in run<br>
    result.startTest(self)<br>  File "C:\PROGRA~1\QGISVA~1\apps\Python27\lib\unittest\runner.py", line 55, in startTest<br>    self.stream.flush()<br>IOError: [Errno 9] Bad file descriptor</font></blockquote></div>
<div><br></div><div>This is a source code of test_init.py</div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<font face="courier new, monospace"># coding=utf-8<br>"""Tests QGIS plugin init."""<br>__author__ = 'Tim Sutton <<a href="mailto:tim@linfiniti.com">tim@linfiniti.com</a>>'<br>__revision__ = '$Format:%H$'<br>
__date__ = '17/10/2010'<br>__license__ = "GPL"<br>__copyright__ = 'Copyright 2012, Australia Indonesia Facility for '<br>__copyright__ += 'Disaster Reduction'<br>import os<br>import unittest<br>
import logging<br>import ConfigParser<br>LOGGER = logging.getLogger('QGIS')<br><br>class TestInit(unittest.TestCase):<br>    """Test that the plugin init is usable for QGIS.<br>    Based heavily on the validator class by Alessandro<br>
    Passoti available here:<br>    <a href="http://github.com/qgis/qgis-django/blob/master/qgis-app/">http://github.com/qgis/qgis-django/blob/master/qgis-app/</a><br>             plugins/validator.py<br>    """<br>
    def test_read_init(self):<br>        """Test that the plugin __init__ will validate on <a href="http://plugins.qgis.org">plugins.qgis.org</a>."""<br>        # You should update this list according to the latest in<br>
        # <a href="https://github.com/qgis/qgis-django/blob/master/qgis-app/">https://github.com/qgis/qgis-django/blob/master/qgis-app/</a><br>        #        plugins/validator.py<br>        required_metadata = [<br>            'name',<br>
            'description',<br>            'version',<br>            'qgisMinimumVersion',<br>            'email',<br>            'author']<br>        file_path = os.path.abspath(os.path.join(<br>
            os.path.dirname(__file__), os.pardir,<br>            'metadata.txt'))<br>        LOGGER.info(file_path)<br>        metadata = []<br>        parser = ConfigParser.ConfigParser()<br>        parser.optionxform = str<br>
        parser.read(file_path)<br>        message = 'Cannot find a section named "general" in %s' % file_path<br>        assert parser.has_section('general'), message<br>        metadata.extend(parser.items('general'))<br>
        for expectation in required_metadata:<br>            message = ('Cannot find metadata "%s" in metadata source (%s).' % (<br>                expectation, file_path))<br>            self.assertIn(expectation, dict(metadata), message)<br>
if __name__ == '__main__':<br>    unittest.main()</font></blockquote></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">Please let </font>me know what is wrong.</div>
<div><br></div><div><br></div><div>Regards,</div><div>BJ Jang.</div><div><br></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><p align="left" style="color:rgb(136,136,136)"><strong><span lang="EN-US"><font face="맑은 고딕">----------------------------------------------------------</font></span></strong></p>
<p align="left" style="color:rgb(136,136,136)"><span lang="EN-US"><font face="맑은 고딕" color="#009900">Open Source GIS Technical Manager / e-Cartographer</font></span><span lang="EN-US" style="font-weight:bold"><br></span><font face="맑은 고딕"><span lang="EN-US" style="font-family:Verdana;color:rgb(79,79,79)"><font size="4">BJ Jang</font></span><b><span lang="EN-US"></span></b></font></p>
<p><font color="#000099" face="맑은 고딕"><b>Gaia3D Inc,</b></font></p></div>
</div>