File: test_new_name.py

package info (click to toggle)
python-fs 2.4.16-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,944 kB
  • sloc: python: 13,048; makefile: 226; sh: 3
file content (27 lines) | stat: -rw-r--r-- 791 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from __future__ import unicode_literals

import unittest
import warnings

from fs.base import _new_name


class TestNewNameDecorator(unittest.TestCase):
    def double(self, n):
        "Double a number"
        return n * 2

    times_2 = _new_name(double, "times_2")

    def test_old_name(self):
        """Test _new_name method issues a warning"""
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            result = self.times_2(2)
            self.assertEqual(len(w), 1)
            self.assertEqual(w[0].category, DeprecationWarning)
            self.assertEqual(
                str(w[0].message),
                "method 'times_2' has been deprecated, please rename to 'double'",
            )
        self.assertEqual(result, 4)