Skip to content

Commit 834009c

Browse files
committed
Merge pull request #19 from DengYiping/temp
Improving code quality by linting unit tests and portions of loklak.py (rebased)
2 parents 4ec73c4 + bf021ae commit 834009c

File tree

5 files changed

+22
-18
lines changed

5 files changed

+22
-18
lines changed

Examples/loklak-tweets-search.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
from loklak import Loklak
2-
import json
32

43
myTweets = Loklak()
54

6-
movieName = raw_input("What movie would you like to search recent tweets for? ") #asks for what user would like to search for
5+
movieName = raw_input("What movie would you like to \
6+
search recent tweets for? ") #asks for what user would like to search for
77

88
index = 1
99
for tweet in myTweets.search(movieName)["statuses"]: #searches movie and finds "statuses" where "text" is under
10-
print '%d%s' %(index, '.') #prints the tweet number
11-
print tweet["text"] + "\n" #prints the text of the tweet and makes a new line
12-
index+=1 #increments index
13-
10+
print("%d%s", index, '.') #prints the tweet number
11+
print("%s\n", tweet["text"]) #prints the text of the tweet and makes a new line
12+
index += 1 #increments index

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## Python Loklak API
2-
[![PyPI version](https://badge.fury.io/py/python-loklak-api.svg)](https://badge.fury.io/py/python-loklak-api)
2+
[![PyPI version](https://badge.fury.io/py/python-loklak-api.svg)](https://badge.fury.io/py/python-loklak-api)
33
[![Build Status](https://travis-ci.org/loklak/python-loklak-api.svg?branch=master)](https://travis-ci.org/loklak/python-loklak-api)
44
[![Code Health](https://landscape.io/github/loklak/python-loklak-api/master/landscape.svg?style=flat)](https://landscape.io/github/loklak/python-loklak-api/master)
55
--------------------------------------------
@@ -73,7 +73,7 @@ Using the object created above, `l.status()` returns a json of the status as fol
7373

7474
##### Settings of the loklak server (strictly only for localhost clients)
7575

76-
Using the object created above `l.settings()` returns a json of the settings being used by the loklak server
76+
Using the class method `settings()` to returns a json of the settings being used by the loklak server
7777

7878
##### Hello test - Check if the server is responding properly and is online
7979

loklak.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Loklak(object):
2525
limit = None
2626
action = None
2727
data = {}
28-
28+
2929
def status(self):
3030
"""Returns the status of the server"""
3131
status_application = 'api/status.json'

sample.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import unittest
2-
import shutil
31
import tempfile
42
from loklak import Loklak
53
from pprint import pprint
@@ -40,8 +38,8 @@
4038
geocode = l.geocode(['New York', 'Singapore'])
4139
pprint(geocode)
4240

43-
# Loklak Map API
44-
png_data = l.map(17.582729, 79.118320, 512, 512, 12, 'Hello')
41+
# Loklak Geographic Map API
42+
png_data = l.get_map(17.582729, 79.118320, 512, 512, 12, 'Hello')
4543
path = tempfile.mkstemp(suffix=".png")[1]
4644
open(path, 'wb').write(png_data)
4745

@@ -110,8 +108,7 @@
110108
pprint(account1)
111109

112110
account2 = l.account('name','update','type')
113-
pprint(account3)
111+
pprint(account2)
114112

115113
# Try call function without name
116114
account3 = l.account(action='update', data='type')
117-

test.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33

44

55
class TestLoklak(unittest.TestCase):
6+
""""test class"""
67
def setUp(self):
8+
"""test proper setup"""
79
self.loklak = Loklak()
810

911
def test_hello(self):
12+
"""test hello instance"""
1013
result = self.loklak.hello()
1114
self.assertEqual(result, {u'status': u'ok'})
1215

1316
def test_geocode(self):
17+
"""test geological features"""
1418
result = self.loklak.geocode()
1519
self.assertEqual(result, '{}')
1620

@@ -26,25 +30,28 @@ def test_geocode(self):
2630
result['locations']['Moscow']['country']
2731
)
2832
self.assertTrue(
29-
type(result['locations']['Moscow']['place']) == list
33+
isinstance(result['locations']['Moscow']['place'], list)
3034
)
3135

3236
def test_peers(self):
37+
"""test finding peers"""
3338
result = self.loklak.peers()
3439
self.assertTrue('peers' in result)
35-
self.assertTrue(type(result['peers']) == list)
40+
self.assertTrue(isinstance(result['peers'], list))
3641
self.assertTrue(len(result['peers']) >= 1)
3742
self.assertEqual(len(result['peers']), result['count'])
3843

3944
def test_search(self):
45+
"""test search result"""
4046
result = self.loklak.search('doctor who')
4147
self.assertTrue('error' in self.loklak.search())
4248
self.assertTrue('statuses' in result)
43-
self.assertTrue(type(result['statuses']) == list)
49+
self.assertTrue(isinstance(result['statuses'], list))
4450
self.assertTrue(len(result['statuses']) >= 1)
4551
self.assertEqual(len(result['statuses']), int(result['search_metadata']['count']))
4652

4753
def test_status(self):
54+
"""test status"""
4855
result = self.loklak.status()
4956

5057
self.assertTrue('index_sizes' in result)
@@ -71,6 +78,7 @@ def test_status(self):
7178
)
7279

7380
def test_user(self):
81+
"""test user"""
7482
result = self.loklak.user('dhruvRamani98')
7583
self.assertTrue('error' in self.loklak.user())
7684
self.assertTrue('user' in result)

0 commit comments

Comments
 (0)