• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

blues / note-python / 14222236649

02 Apr 2025 02:30PM UTC coverage: 92.458% (+0.6%) from 91.822%
14222236649

push

github

web-flow
Merge pull request #102 from blues/alex-improve-test-cov

Improve test coverage

75 of 79 new or added lines in 4 files covered. (94.94%)

2182 of 2360 relevant lines covered (92.46%)

4.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.23
/test/test_validators.py
1
import unittest
5✔
2
import sys
5✔
3
from unittest.mock import MagicMock, patch
5✔
4
from notecard import Notecard
5✔
5
from notecard.validators import validate_card_object
5✔
6

7

8
class TestValidators(unittest.TestCase):
5✔
9

10
    def setUp(self):
5✔
11
        self.mock_notecard = MagicMock(spec=Notecard)
5✔
12
        # Store original implementation name
13
        self.original_implementation = sys.implementation.name
5✔
14
        # Clear the module from sys.modules to force reload
15
        if 'notecard.validators' in sys.modules:
5✔
16
            del sys.modules['notecard.validators']
5✔
17

18
    def tearDown(self):
5✔
19
        # Restore original implementation
20
        sys.implementation.name = self.original_implementation
5✔
21
        # Clear the module again
22
        if 'notecard.validators' in sys.modules:
5✔
23
            del sys.modules['notecard.validators']
5✔
24

25
    def test_validate_card_object_with_valid_notecard(self):
5✔
26
        @validate_card_object
5✔
27
        def test_func(card):
5✔
28
            return True
5✔
29

30
        result = test_func(self.mock_notecard)
5✔
31
        self.assertTrue(result)
5✔
32

33
    def test_validate_card_object_with_invalid_notecard(self):
5✔
34
        @validate_card_object
5✔
35
        def test_func(card):
5✔
NEW
36
            return True
×
37

38
        with self.assertRaises(Exception) as context:
5✔
39
            test_func("not a notecard")
5✔
40
        self.assertEqual(str(context.exception), "Notecard object required")
5✔
41

42
    @unittest.skipIf(sys.implementation.name != "cpython", "Function metadata only preserved in CPython")
5✔
43
    def test_validate_card_object_preserves_metadata(self):
5✔
44
        @validate_card_object
5✔
45
        def test_func(card):
5✔
46
            """Test function docstring."""
NEW
47
            return True
×
48

49
        self.assertEqual(test_func.__name__, "test_func")
5✔
50
        self.assertEqual(test_func.__doc__, "Test function docstring.")
5✔
51

52
    def test_validate_card_object_non_cpython(self):
5✔
53
        sys.implementation.name = 'non-cpython'
5✔
54
        from notecard.validators import validate_card_object
5✔
55

56
        @validate_card_object
5✔
57
        def test_func(card):
5✔
58
            return True
5✔
59

60
        result = test_func(self.mock_notecard)
5✔
61
        self.assertTrue(result)
5✔
62

63
    def test_validate_card_object_non_cpython_with_invalid_notecard(self):
5✔
64
        sys.implementation.name = 'non-cpython'
5✔
65
        from notecard.validators import validate_card_object
5✔
66

67
        @validate_card_object
5✔
68
        def test_func(card):
5✔
NEW
69
            return True
×
70

71
        with self.assertRaises(Exception) as context:
5✔
72
            test_func("not a notecard")
5✔
73
        self.assertEqual(str(context.exception), "Notecard object required")
5✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc