Skip to content

Commit 9121047

Browse files
hdk5python273
authored andcommitted
Full review and some refactoring (#124)
1 parent c3b4f6f commit 9121047

16 files changed

Lines changed: 425 additions & 233 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ MANIFEST
88
.pydevproject
99
.settings/
1010
testing/
11-
tests/
11+
tests1/
1212
vk_config.json
1313
vk_config.v2.json

examples/messages_bot/messages_bot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def main():
3434
longpoll = VkLongPoll(vk_session)
3535

3636
for event in longpoll.listen():
37-
if event.type == VkEventType.MESSAGE_NEW and event.to_me:
37+
if event.type == VkEventType.MESSAGE_NEW and event.to_me and event.text:
3838
print('id{}: "{}"'.format(event.user_id, event.text), end=' ')
3939

4040
response = session.get(

jconfig/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ def __getattr__(self, name):
2424
__getitem__ = __getattr__
2525

2626
def __setattr__(self, name, value):
27-
if name in self.__slots__:
28-
return super(BaseConfig, self).__setattr__(name, value)
29-
30-
self._section[name] = value
27+
try:
28+
super(BaseConfig, self).__setattr__(name, value)
29+
except AttributeError:
30+
self._section[name] = value
3131

3232
__setitem__ = __setattr__
3333

jconfig/jconfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
class Config(BaseConfig):
1616

17-
__slots__ = BaseConfig.__slots__ + ('_filename',)
17+
__slots__ = ('_filename',)
1818

1919
def __init__(self, section, filename='.jconfig'):
2020
self._filename = filename

jconfig/memory.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212

1313
class MemoryConfig(BaseConfig):
14+
15+
__slots__ = tuple()
16+
1417
def load(self, settings=None, **kwargs):
1518
return {} if settings is None else settings
1619

requirements_dev.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pytest
2+
pytest-mock

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
license='Apache License, Version 2.0, see LICENSE file',
2323

2424
packages=['vk_api', 'jconfig'],
25-
install_requires=['requests', 'enum34'],
25+
install_requires=['requests', 'enum34', 'beautifulsoup4'],
2626

2727
classifiers=[
2828
'License :: OSI Approved :: Apache Software License',

tests/__init__.py

Whitespace-only changes.

tests/test_jconfig.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from jconfig.memory import MemoryConfig
2+
3+
4+
def test_config_section():
5+
c = MemoryConfig('secret')
6+
7+
assert 'secret' in c._settings
8+
9+
c.test = 'hello!'
10+
11+
assert c['test'] == 'hello!'
12+
assert c.test == 'hello!'
13+
assert c._section == {'test': 'hello!'}
14+
15+
c['test'] = '42'
16+
17+
assert c['test'] == '42'
18+
assert c.test == '42'
19+
assert c._section == {'test': '42'}

vk_api/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
from .enums import *
23
from .exceptions import *
34
from .requests_pool import VkRequestsPool
45
from .tools import VkTools

0 commit comments

Comments
 (0)