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

praw-dev / praw / 3768928224

pending completion
3768928224

Pull #1923

github

GitHub
Merge 33b610e6e into ffe9f71d6
Pull Request #1923: Improve tests, clean up test code, and sort test functions/classes

4109 of 4109 relevant lines covered (100.0%)

4.0 hits per line

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

100.0
/praw/models/base.py
1
"""Provide the PRAWBase superclass."""
2
from copy import deepcopy
4✔
3
from typing import TYPE_CHECKING, Any, Dict, Optional
4✔
4

5
if TYPE_CHECKING:  # pragma: no cover
6
    import praw
7

8

9
class PRAWBase:
4✔
10
    """Superclass for all models in PRAW."""
11

12
    @staticmethod
4✔
13
    def _safely_add_arguments(*, arguments, key, **new_arguments):
3✔
14
        """Replace arguments[key] with a deepcopy and update.
15

16
        This method is often called when new parameters need to be added to a request.
17
        By calling this method and adding the new or updated parameters we can insure we
18
        don't modify the dictionary passed in by the caller.
19

20
        """
21
        value = deepcopy(arguments[key]) if key in arguments else {}
4✔
22
        value.update(new_arguments)
4✔
23
        arguments[key] = value
4✔
24

25
    @classmethod
4✔
26
    def parse(cls, data: Dict[str, Any], reddit: "praw.Reddit") -> Any:
4✔
27
        """Return an instance of ``cls`` from ``data``.
28

29
        :param data: The structured data.
30
        :param reddit: An instance of :class:`.Reddit`.
31

32
        """
33
        return cls(reddit, _data=data)
4✔
34

35
    def __init__(self, reddit: "praw.Reddit", _data: Optional[Dict[str, Any]]):
4✔
36
        """Initialize a :class:`.PRAWBase` instance.
37

38
        :param reddit: An instance of :class:`.Reddit`.
39

40
        """
41
        self._reddit = reddit
4✔
42
        if _data:
4✔
43
            for attribute, value in _data.items():
4✔
44
                setattr(self, attribute, value)
4✔
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