"""Tests for cherrypy/lib/httputil.py."""

import unittest
from cherrypy.lib import httputil


class UtilityTests(unittest.TestCase):

    def test_urljoin(self):
        # Test all slash+atom combinations for SCRIPT_NAME and PATH_INFO
        self.assertEqual(httputil.urljoin('/sn/', '/pi/'), '/sn/pi/')
        self.assertEqual(httputil.urljoin('/sn/', '/pi'), '/sn/pi')
        self.assertEqual(httputil.urljoin('/sn/', '/'), '/sn/')
        self.assertEqual(httputil.urljoin('/sn/', ''), '/sn/')
        self.assertEqual(httputil.urljoin('/sn', '/pi/'), '/sn/pi/')
        self.assertEqual(httputil.urljoin('/sn', '/pi'), '/sn/pi')
        self.assertEqual(httputil.urljoin('/sn', '/'), '/sn/')
        self.assertEqual(httputil.urljoin('/sn', ''), '/sn')
        self.assertEqual(httputil.urljoin('/', '/pi/'), '/pi/')
        self.assertEqual(httputil.urljoin('/', '/pi'), '/pi')
        self.assertEqual(httputil.urljoin('/', '/'), '/')
        self.assertEqual(httputil.urljoin('/', ''), '/')
        self.assertEqual(httputil.urljoin('', '/pi/'), '/pi/')
        self.assertEqual(httputil.urljoin('', '/pi'), '/pi')
        self.assertEqual(httputil.urljoin('', '/'), '/')
        self.assertEqual(httputil.urljoin('', ''), '/')


if __name__ == '__main__':
    unittest.main()

"""Tests for ``cherrypy.lib.httputil``."""
import pytest

from cherrypy.lib import httputil


class TestUtility(object):
    @pytest.mark.parametrize(
        'script_name,path_info,expected_url',
        [
            ('/sn/', '/pi/', '/sn/pi/'),
            ('/sn/', '/pi', '/sn/pi'),
            ('/sn/', '/', '/sn/'),
            ('/sn/', '', '/sn/'),
            ('/sn', '/pi/', '/sn/pi/'),
            ('/sn', '/pi', '/sn/pi'),
            ('/sn', '/', '/sn/'),
            ('/sn', '', '/sn'),
            ('/', '/pi/', '/pi/'),
            ('/', '/pi', '/pi'),
            ('/', '/', '/'),
            ('/', '', '/'),
            ('', '/pi/', '/pi/'),
            ('', '/pi', '/pi'),
            ('', '/', '/'),
            ('', '', '/'),
        ]
    )
    def test_urljoin(self, script_name, path_info, expected_url):
        """Test all slash+atom combinations for SCRIPT_NAME and PATH_INFO."""
        actual_url = httputil.urljoin(script_name, path_info)
        assert actual_url == expected_url

Rewrite httputil test module via pytest
Rewrite httputil test module via pytest

- """Tests for cherrypy/lib/httputil.py."""
+ """Tests for ``cherrypy.lib.httputil``."""
+ import pytest
  
- import unittest
  from cherrypy.lib import httputil
  
  
- class UtilityTests(unittest.TestCase):
+ class TestUtility(object):
+     @pytest.mark.parametrize(
+         'script_name,path_info,expected_url',
+         [
+             ('/sn/', '/pi/', '/sn/pi/'),
+             ('/sn/', '/pi', '/sn/pi'),
+             ('/sn/', '/', '/sn/'),
+             ('/sn/', '', '/sn/'),
+             ('/sn', '/pi/', '/sn/pi/'),
+             ('/sn', '/pi', '/sn/pi'),
+             ('/sn', '/', '/sn/'),
+             ('/sn', '', '/sn'),
+             ('/', '/pi/', '/pi/'),
+             ('/', '/pi', '/pi'),
+             ('/', '/', '/'),
+             ('/', '', '/'),
+             ('', '/pi/', '/pi/'),
+             ('', '/pi', '/pi'),
+             ('', '/', '/'),
+             ('', '', '/'),
+         ]
+     )
+     def test_urljoin(self, script_name, path_info, expected_url):
+         """Test all slash+atom combinations for SCRIPT_NAME and PATH_INFO."""
+         actual_url = httputil.urljoin(script_name, path_info)
+         assert actual_url == expected_url
  
-     def test_urljoin(self):
-         # Test all slash+atom combinations for SCRIPT_NAME and PATH_INFO
-         self.assertEqual(httputil.urljoin('/sn/', '/pi/'), '/sn/pi/')
-         self.assertEqual(httputil.urljoin('/sn/', '/pi'), '/sn/pi')
-         self.assertEqual(httputil.urljoin('/sn/', '/'), '/sn/')
-         self.assertEqual(httputil.urljoin('/sn/', ''), '/sn/')
-         self.assertEqual(httputil.urljoin('/sn', '/pi/'), '/sn/pi/')
-         self.assertEqual(httputil.urljoin('/sn', '/pi'), '/sn/pi')
-         self.assertEqual(httputil.urljoin('/sn', '/'), '/sn/')
-         self.assertEqual(httputil.urljoin('/sn', ''), '/sn')
-         self.assertEqual(httputil.urljoin('/', '/pi/'), '/pi/')
-         self.assertEqual(httputil.urljoin('/', '/pi'), '/pi')
-         self.assertEqual(httputil.urljoin('/', '/'), '/')
-         self.assertEqual(httputil.urljoin('/', ''), '/')
-         self.assertEqual(httputil.urljoin('', '/pi/'), '/pi/')
-         self.assertEqual(httputil.urljoin('', '/pi'), '/pi')
-         self.assertEqual(httputil.urljoin('', '/'), '/')
-         self.assertEqual(httputil.urljoin('', ''), '/')
- 
- 
- if __name__ == '__main__':
-     unittest.main()
- 
Rewrite httputil test module via pytest
## Code Before:
"""Tests for cherrypy/lib/httputil.py."""

import unittest
from cherrypy.lib import httputil


class UtilityTests(unittest.TestCase):

    def test_urljoin(self):
        # Test all slash+atom combinations for SCRIPT_NAME and PATH_INFO
        self.assertEqual(httputil.urljoin('/sn/', '/pi/'), '/sn/pi/')
        self.assertEqual(httputil.urljoin('/sn/', '/pi'), '/sn/pi')
        self.assertEqual(httputil.urljoin('/sn/', '/'), '/sn/')
        self.assertEqual(httputil.urljoin('/sn/', ''), '/sn/')
        self.assertEqual(httputil.urljoin('/sn', '/pi/'), '/sn/pi/')
        self.assertEqual(httputil.urljoin('/sn', '/pi'), '/sn/pi')
        self.assertEqual(httputil.urljoin('/sn', '/'), '/sn/')
        self.assertEqual(httputil.urljoin('/sn', ''), '/sn')
        self.assertEqual(httputil.urljoin('/', '/pi/'), '/pi/')
        self.assertEqual(httputil.urljoin('/', '/pi'), '/pi')
        self.assertEqual(httputil.urljoin('/', '/'), '/')
        self.assertEqual(httputil.urljoin('/', ''), '/')
        self.assertEqual(httputil.urljoin('', '/pi/'), '/pi/')
        self.assertEqual(httputil.urljoin('', '/pi'), '/pi')
        self.assertEqual(httputil.urljoin('', '/'), '/')
        self.assertEqual(httputil.urljoin('', ''), '/')


if __name__ == '__main__':
    unittest.main()

## Instruction:
Rewrite httputil test module via pytest
## Code After:
"""Tests for ``cherrypy.lib.httputil``."""
import pytest

from cherrypy.lib import httputil


class TestUtility(object):
    @pytest.mark.parametrize(
        'script_name,path_info,expected_url',
        [
            ('/sn/', '/pi/', '/sn/pi/'),
            ('/sn/', '/pi', '/sn/pi'),
            ('/sn/', '/', '/sn/'),
            ('/sn/', '', '/sn/'),
            ('/sn', '/pi/', '/sn/pi/'),
            ('/sn', '/pi', '/sn/pi'),
            ('/sn', '/', '/sn/'),
            ('/sn', '', '/sn'),
            ('/', '/pi/', '/pi/'),
            ('/', '/pi', '/pi'),
            ('/', '/', '/'),
            ('/', '', '/'),
            ('', '/pi/', '/pi/'),
            ('', '/pi', '/pi'),
            ('', '/', '/'),
            ('', '', '/'),
        ]
    )
    def test_urljoin(self, script_name, path_info, expected_url):
        """Test all slash+atom combinations for SCRIPT_NAME and PATH_INFO."""
        actual_url = httputil.urljoin(script_name, path_info)
        assert actual_url == expected_url
