Skip to content

Commit 9e56217

Browse files
committed
Merge pull request #2 from brazilian-dev/json-generator
Json generator
2 parents 9a14dd0 + 8ec6b8d commit 9e56217

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
language: python
2+
python:
3+
- "3.3"
4+
5+
#run tests
6+
#script: python -m unittest

source/json-generator.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import fnmatch
5+
from json import dumps, load
6+
7+
def writeJson(data, filename):
8+
try:
9+
jsondata = dumps(data, indent=2, skipkeys=True, sort_keys=True)
10+
fd = open(filename, 'w')
11+
fd.write(jsondata)
12+
fd.close()
13+
except:
14+
print 'ERROR writing', filename
15+
pass
16+
17+
def getDir(path, ext):
18+
matches = []
19+
for root, dirnames, filenames in os.walk(path):
20+
for filename in fnmatch.filter(filenames, ext):
21+
matches.append(os.path.join(root, filename))
22+
return matches
23+
24+
25+
result = []
26+
for file in getDir('../snippets/', '*.sublime-snippet'):
27+
line = open(file)
28+
content = line.read()
29+
trigger = content.split('<tabTrigger>')[1].split('</tabTrigger>')[0]
30+
description = content.split('<description>')[1].split('</description>')[0]
31+
32+
result.append({'trigger':trigger, 'description':description})
33+
34+
writeJson(result, "../snippets.json")
35+

tests/test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python3
2+
3+
import unittest
4+
5+
class TestStringMethods(unittest.TestCase):
6+
7+
def test_upper(self):
8+
self.assertEqual('foo'.upper(), 'FOO')
9+
10+
def test_isupper(self):
11+
self.assertTrue('FOO'.isupper())
12+
self.assertFalse('Foo'.isupper())
13+
14+
def test_split(self):
15+
s = 'hello world'
16+
self.assertEqual(s.split(), ['hello', 'world'])
17+
# check that s.split fails when the separator is not a string
18+
with self.assertRaises(TypeError):
19+
s.split(2)
20+
21+
if __name__ == '__main__':
22+
unittest.main()

tests/unittest_compat.py

Whitespace-only changes.

0 commit comments

Comments
 (0)