Changeset 26:14c16e5cbe03 in pyenvjasmine


Ignore:
Timestamp:
Jan 18, 2018, 12:22:26 PM (3 years ago)
Author:
Borja Lopez <borja@…>
Branch:
default
Phase:
public
Message:

Replaced nose with py.test and adapted all existing tests

Files:
3 added
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • README.rst

    r24 r26  
    3838want to test), install pyenvjasmine and then run::
    3939
    40     nosetests --cover-package=pyenvjasmine --cover-erase \
    41     --with-coverage --with-doctest $*
    42 
    43 .. note::
    44 
    45    If you have installed pyenvjasmine in *development mode*, you can simply
    46    run::
    47 
    48      nosetests -c nose.cfg
    49 
    50    to run the tests from within the pyenvjasmine sources directory.
     40  py.test
    5141
    5242
     
    6151from the js tests on the console. Something like this::
    6252
    63     import unittest
     53    import pytest
    6454    from pyenvjasmine.runner import Runner
    6555
    66     class JavaScriptTests(unittest.TestCase):
     56    class TestJavaScript(object):
    6757        def test_my_javascript(self):
    6858            runner = Runner(
    6959                testdir='/path/to/my/testdir',
    7060                configfile='relative/path/to/configfile')
    71             runner.run(capture_output=False)
    72 
    73 
    74 If you want a more integrated test control, you could set capture_output to
    75 True, then parse the test output that is returned from the run() method, with
    76 something like this::
    77 
    78     import unittest
    79     from pyenvjasmine.runner import Runner
    80 
    81     class JavaScriptTests(unittest.TestCase):
    82         def test_my_javascript_no_output(self):
    83             runner = Runner(
    84                 testdir='/path/to/my/testdir',
    85                 configfile='relative/path/to/configfile')
    86             res = runner.run(capture_output=True)
    87             lines = res.splitlines()
    88             self.assertTrue('Failed: 0' in lines)
     61            success, stdout = runner.run()
     62            # assert on success, will be true if tests passed, False if any
     63            # test failed
     64            assert success
     65            # you can inspect stdout if you want to get more info, but it
     66            # will be printed to the console stdout anyway
     67            assert b'Total: 120' in stdout
    8968
    9069
  • pyenvjasmine/tests/test_runner.py

    r24 r26  
    1 import unittest
    21import os
     2import pytest
    33
    4 from pyenvjasmine.runner import Runner
     4from pyenvjasmine.runner import Runner, get_environment
    55
    66
    7 class RunnerTests(unittest.TestCase):
    8     def setUp(self):
    9         pass
    10 
    11     def tearDown(self):
    12         pass
     7class TestsRunner(object):
    138
    149    def test_runner_defaults(self):
     
    1712        """
    1813        jstests = Runner()
    19         output = jstests.run()
     14        success, stdout = jstests.run()
     15        assert success
    2016        # output is the resulting stdout from a subprocess call, which is a
    2117        # bytes object, hence the b'' for the checks
    22         self.assertTrue(b'Failed: 0' in output)
    23         self.assertTrue(b'Passed: 5' in output)
     18        assert b'Failed: 0' in stdout
     19        assert b'Passed: 5' in stdout
    2420
    2521    def test_runner_params(self):
     
    3632            configfile=conf_file,
    3733        )
    38         output = jstests.run(spec='tests/specs/test_demo.spec.js')
    39         lines = output.splitlines()
     34        success, stdout = jstests.run(spec='tests/specs/test_demo.spec.js')
     35        lines = stdout.splitlines()
    4036        # output is the resulting stdout from a subprocess call, which is a
    4137        # bytes object, hence the b'' in the endswith/startswith calls
    42         self.assertTrue(lines[0].endswith(b'specs/test_demo.spec.js'),
    43             "wrong output: %s" % str(output))
    44         self.assertTrue(lines[1].startswith(b'[  Envjs/1.6 (Rhino;'),
    45             "wrong output: %s" % str(output))
    46         self.assertTrue(b'Passed: 4' in lines)
    47         self.assertTrue(b'Failed: 0' in lines)
    48         self.assertTrue(b'Total : 4' in lines)
     38        assert lines[0].endswith(b'specs/test_demo.spec.js')
     39        assert lines[1].startswith(b'[  Envjs/1.6 (Rhino;')
     40        assert b'Passed: 4' in lines
     41        assert b'Failed: 0' in lines
     42        assert b'Total : 4' in lines
    4943
    5044    def test_write_browser_htmlfile_markup_is_correct(self):
     
    6559        with open("browser.runner.html",'r') as file:
    6660            actual = file.read()
    67             self.assertEqual(expected, actual)
     61            assert expected == actual
    6862
    6963    def test_runner_with_browser_configfile(self):
     
    8074            browser_configfile=browser_conf_file
    8175        )
    82         jstests.run(spec='tests/specs/test_demo.spec.js')
     76        success, stdout = jstests.run(spec='tests/specs/test_demo.spec.js')
     77        assert not success
    8378
    8479    def test_get_environment(self):
     
    8883        so monkey patching the old way.
    8984        """
    90         from pyenvjasmine.runner import get_environment
    91         import os
    9285        old_os_name = os.name
    9386        try:
    9487            os.name = 'nt'
    9588            res = get_environment()
    96             self.assertEqual(res, '--environment=WIN')
     89            assert res == '--environment=WIN'
    9790            os.name = 'posix'
    9891            res = get_environment()
    99             self.assertEqual(res, '--environment=UNIX')
     92            assert res == '--environment=UNIX'
    10093        finally:
    10194            os.name = old_os_name
    102 
    103     def test_not_capture_output(self):
    104         """
    105         Running a test without capturing output
    106         """
    107         jstests = Runner()
    108         output = jstests.run(capture_output=False)
    109         self.assertEqual(output, None)
  • setup.py

    r24 r26  
    55
    66requires = [
    7     'nose',
    8     'coverage'
     7    'coverage',
     8    'pytest',
     9    'pytest-cov'
    910]
    1011
Note: See TracChangeset for help on using the changeset viewer.