Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import topgg

from sys import stdout
import asyncio
import os

INDENTATION = 2


def is_local(data: object) -> bool:
return getattr(data, '__module__', '').startswith('topgg')


def _test_attributes(obj: object, indent_level: int) -> None:
for name in getattr(obj.__class__, '__slots__', ()):
stdout.write(f'{" " * indent_level}{obj.__class__.__name__}.{name}')
data = getattr(obj, name)

if isinstance(data, list) and data:
stdout.write('[0] -> ')

for i, each in enumerate(data):
if i > 0:
stdout.write(
f'{" " * indent_level}{obj.__class__.__name__}.{name}[{i}] -> '
)

print(repr(each))
_test_attributes(each, indent_level + INDENTATION)

continue

print(f' -> {data!r}')

if is_local(data):
_test_attributes(data, indent_level + INDENTATION)


def test_attributes(obj: object) -> None:
print(f'{obj!r} -> ')
_test_attributes(obj, INDENTATION)


async def run() -> None:
async with topgg.DBLClient(os.getenv('TOPGG_TOKEN')) as tg:
bot = await tg.get_bot_info(432610292342587392)

test_attributes(bot)

await asyncio.sleep(1)
bots = await tg.get_bots(limit=250, offset=50, sort=topgg.SortBy.MONTHLY_VOTES)

for b in bots:
test_attributes(b)

await asyncio.sleep(1)
await tg.post_guild_count(topgg.StatsWrapper(2))

await asyncio.sleep(1)
posted_stats = await tg.get_guild_count()

assert posted_stats.server_count == 2
test_attributes(posted_stats)

await asyncio.sleep(1)
voters = await tg.get_bot_votes()

for voter in voters:
test_attributes(voter)

await asyncio.sleep(1)
is_weekend = await tg.get_weekend_status()

assert isinstance(is_weekend, bool)

await asyncio.sleep(1)
has_voted = await tg.get_user_vote(661200758510977084)

assert isinstance(has_voted, bool)


if __name__ == '__main__':
asyncio.run(run())
51 changes: 51 additions & 0 deletions test_autoposter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
ORIGINAL_INTERVAL_INSTRUCTION = 'await asyncio.sleep(self.interval)'
MODIFIED_INTERVAL_INSTRUCTION = 'await asyncio.sleep(2)'


def replace_autopost_file(former: str, latter: str) -> None:
autopost_file_contents = None

with open('./topgg/autopost.py', 'r') as autopost_file:
autopost_file_contents = autopost_file.read().replace(former, latter)

with open('./topgg/autopost.py', 'w') as autopost_file:
autopost_file.write(autopost_file_contents)


replace_autopost_file(ORIGINAL_INTERVAL_INSTRUCTION, MODIFIED_INTERVAL_INSTRUCTION)


import topgg

import asyncio
import os


async def run() -> None:
try:
async with topgg.DBLClient(os.getenv('TOPGG_TOKEN')) as tg:
autoposter = tg.autopost()

@autoposter.stats
def get_guild_count() -> int:
return topgg.StatsWrapper(2)

@autoposter.on_success
def success() -> None:
print('Successfully posted statistics to the Top.gg API!')

@autoposter.on_error
def error(exc: Exception) -> None:
print(f'Error: {exc!r}')

autoposter.start()

await asyncio.sleep(15)
finally:
replace_autopost_file(
MODIFIED_INTERVAL_INSTRUCTION, ORIGINAL_INTERVAL_INSTRUCTION
)


if __name__ == '__main__':
asyncio.run(run())
95 changes: 0 additions & 95 deletions tests/test_autopost.py

This file was deleted.

54 changes: 0 additions & 54 deletions tests/test_client.py

This file was deleted.

60 changes: 0 additions & 60 deletions tests/test_data_container.py

This file was deleted.

28 changes: 0 additions & 28 deletions tests/test_ratelimiter.py

This file was deleted.

Loading
Loading