Repository: RustPython/RustPython
File: Lib/test/test_types.py (Python)

Code before:
import sys
import textwrap
import types
import unittest.mock
import weakref
import typing

import unittest  # XXX: RUSTPYTHON; importing to be able to skip tests

c_types = import_fresh_module('types', fresh=['_types'])
py_types = import_fresh_module('types', blocked=['_types'])

T = typing.TypeVar("T")

class Example:
    pass

class Forward: ...

def clear_typing_caches():
    for f in typing._cleanups:
        f()


class TypesTests(unittest.TestCase):

    def test_names(self):
        c_only_names = {'CapsuleType'}
        ignored = {'new_class', 'resolve_bases', 'prepare_class',
                   'get_original_bases', 'DynamicClassAttribute', 'coroutine'}

        for name in c_types.__all__:
            if name not in c_only_names | ignored:
                self.assertIs(getattr(c_types, name), getattr(py_types, name))

        all_names = ignored | {
            'AsyncGeneratorType', 'BuiltinFunctionType', 'BuiltinMethodType',
            'CapsuleType', 'CellType', 'ClassMethodDescriptorType', 'CodeType',
            'CoroutineType', 'EllipsisType', 'FrameType', 'FunctionType',
            'GeneratorType', 'GenericAlias', 'GetSetDescriptorType',
            'LambdaType', 'MappingProxyType', 'MemberDescriptorType',
            'MethodDescriptorType', 'MethodType', 'MethodWrapperType',
            'ModuleType', 'NoneType', 'NotImplementedType', 'SimpleNamespace',
            'TracebackType', 'UnionType', 'WrapperDescriptorType',
        }
        self.assertEqual(all_names, set(c_types.__all__))
        self.assertEqual(all_names - c_only_names, set(py_types.__all__))

    def test_truth_values(self):
        if None: self.fail('None is true instead of false')
        if 0: self.fail('0 is true instead of false')

Review comment (suggestion):
```suggestion

    @unittest.skipUnless(c_types, "TODO: RUSTPYTHON; requires _types module")
```

Code after:
import sys
import textwrap
import types
import unittest.mock
import weakref
import typing

import unittest  # XXX: RUSTPYTHON; importing to be able to skip tests

c_types = import_fresh_module('types', fresh=['_types'])
py_types = import_fresh_module('types', blocked=['_types'])

T = typing.TypeVar("T")

class Example:
    pass

class Forward: ...

def clear_typing_caches():
    for f in typing._cleanups:
        f()


class TypesTests(unittest.TestCase):

    @unittest.skipUnless(c_types, "TODO: RUSTPYTHON; requires _types module")
    def test_names(self):
        c_only_names = {'CapsuleType'}
        ignored = {'new_class', 'resolve_bases', 'prepare_class',
                   'get_original_bases', 'DynamicClassAttribute', 'coroutine'}

        for name in c_types.__all__:
            if name not in c_only_names | ignored:
                self.assertIs(getattr(c_types, name), getattr(py_types, name))

        all_names = ignored | {
            'AsyncGeneratorType', 'BuiltinFunctionType', 'BuiltinMethodType',
            'CapsuleType', 'CellType', 'ClassMethodDescriptorType', 'CodeType',
            'CoroutineType', 'EllipsisType', 'FrameType', 'FunctionType',
            'GeneratorType', 'GenericAlias', 'GetSetDescriptorType',
            'LambdaType', 'MappingProxyType', 'MemberDescriptorType',
            'MethodDescriptorType', 'MethodType', 'MethodWrapperType',
            'ModuleType', 'NoneType', 'NotImplementedType', 'SimpleNamespace',
            'TracebackType', 'UnionType', 'WrapperDescriptorType',
        }
        self.assertEqual(all_names, set(c_types.__all__))
        self.assertEqual(all_names - c_only_names, set(py_types.__all__))

    def test_truth_values(self):
        if None: self.fail('None is true instead of false')