Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_equality(self):
subreddit1 = Subreddit(
self.reddit, _data={"display_name": "dummy1", "n": 1}
)
subreddit2 = Subreddit(
self.reddit, _data={"display_name": "Dummy1", "n": 2}
)
subreddit3 = Subreddit(
self.reddit, _data={"display_name": "dummy3", "n": 2}
)
assert subreddit1 == subreddit1
assert subreddit2 == subreddit2
assert subreddit3 == subreddit3
assert subreddit1 == subreddit2
assert subreddit2 != subreddit3
assert subreddit1 != subreddit3
assert "dummy1" == subreddit1
assert subreddit2 == "dummy1"
def test_hash(self):
emoji1 = Emoji(
self.reddit, subreddit=Subreddit(self.reddit, "a"), name="x"
)
emoji2 = Emoji(
self.reddit, subreddit=Subreddit(self.reddit, "a"), name="2"
)
emoji3 = Emoji(
self.reddit, subreddit=Subreddit(self.reddit, "b"), name="1"
)
emoji4 = Emoji(
self.reddit, subreddit=Subreddit(self.reddit, "A"), name="x"
)
emoji5 = Emoji(
self.reddit, subreddit=Subreddit(self.reddit, "a"), name="X"
)
emoji6 = Emoji(
self.reddit, subreddit=Subreddit(self.reddit, "b"), name="x"
)
assert hash(emoji1) == hash(emoji1)
assert hash(emoji2) == hash(emoji2)
assert hash(emoji3) == hash(emoji3)
assert hash(emoji1) != hash(emoji2)
assert hash(emoji1) != hash(emoji3)
assert hash(emoji1) == hash(emoji4)
assert hash(emoji1) != hash(emoji5)
assert hash(emoji1) != hash(emoji6)
def test_hash(self):
subreddit1 = Subreddit(
self.reddit, _data={"display_name": "dummy1", "n": 1}
)
subreddit2 = Subreddit(
self.reddit, _data={"display_name": "Dummy1", "n": 2}
)
subreddit3 = Subreddit(
self.reddit, _data={"display_name": "dummy3", "n": 2}
)
assert hash(subreddit1) == hash(subreddit1)
assert hash(subreddit2) == hash(subreddit2)
assert hash(subreddit3) == hash(subreddit3)
assert hash(subreddit1) == hash(subreddit2)
assert hash(subreddit2) != hash(subreddit3)
assert hash(subreddit1) != hash(subreddit3)
def test_equality(self):
page1 = WikiPage(
self.reddit, subreddit=Subreddit(self.reddit, "a"), name="x"
)
page2 = WikiPage(
self.reddit, subreddit=Subreddit(self.reddit, "a"), name="2"
)
page3 = WikiPage(
self.reddit, subreddit=Subreddit(self.reddit, "b"), name="1"
)
page4 = WikiPage(
self.reddit, subreddit=Subreddit(self.reddit, "A"), name="x"
)
page5 = WikiPage(
self.reddit, subreddit=Subreddit(self.reddit, "a"), name="X"
)
assert page1 == page1
assert page2 == page2
assert page3 == page3
assert page1 != page2
assert page1 != page3
assert page1 == page4
assert page1 == page5
def test_upload_banner_additional_image(self):
subreddit = Subreddit(self.reddit, display_name="name")
with pytest.raises(ValueError):
subreddit.stylesheet.upload_banner_additional_image(
"dummy_path", align="asdf"
)
def test_construct_failure(self):
message = "Either `display_name` or `_data` must be provided."
with pytest.raises(TypeError) as excinfo:
Subreddit(self.reddit)
assert str(excinfo.value) == message
with pytest.raises(TypeError) as excinfo:
Subreddit(self.reddit, "dummy", {"id": "dummy"})
assert str(excinfo.value) == message
def test_fullname(self):
subreddit = Subreddit(
self.reddit, _data={"display_name": "name", "id": "dummy"}
)
assert subreddit.fullname == "t5_dummy"
def test_pickle(self):
emoji = Emoji(
self.reddit, subreddit=Subreddit(self.reddit, "a"), name="x"
)
for level in range(pickle.HIGHEST_PROTOCOL + 1):
other = pickle.loads(pickle.dumps(emoji, protocol=level))
assert emoji == other
def test_construct_failure(self):
message = "Either `display_name` or `_data` must be provided."
with pytest.raises(TypeError) as excinfo:
Subreddit(self.reddit)
assert str(excinfo.value) == message
with pytest.raises(TypeError) as excinfo:
Subreddit(self.reddit, "dummy", {"id": "dummy"})
assert str(excinfo.value) == message
def test_karma(self):
self.reddit.read_only = False
with self.recorder.use_cassette("TestUser.test_karma"):
karma = self.reddit.user.karma()
assert isinstance(karma, dict)
for subreddit in karma:
assert isinstance(subreddit, Subreddit)
keys = sorted(karma[subreddit].keys())
assert ["comment_karma", "link_karma"] == keys