Skip to content

Commit

Permalink
moar things
Browse files Browse the repository at this point in the history
  • Loading branch information
jkloo committed Feb 16, 2014
1 parent 68d18ce commit d17cd70
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 83 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
34 changes: 33 additions & 1 deletion batchy.sublime-project
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
{ "folders": [ { "path": ".", "file_exclude_patterns": [ "*.pyc", "*.sublime-workspace", "*.sublime-project", ".gitignore" ], "folder_exclude_patterns": [ "build", "*.egg-info", "dist" ] } ], "settings": { "font_size": 10, "tab_size": 4, "indent_spaces": true, "rulers": [120], "translate_tabs_to_spaces": true, "trim_automatic_white_space": true, "bold_folder_labels": true, "ensure_newline_at_eof_on_save": true } }
{
"folders":
[
{
"path": ".",
"file_exclude_patterns":
[
"*.pyc",
"*.sublime-workspace",
"*.sublime-project",
".gitignore"
],
"folder_exclude_patterns":
[
"build",
"*.egg-info",
"dist"
]
}
],
"settings":
{
"font_size": 10,
"tab_size": 4,
"indent_spaces": true,
"rulers": [120],
"translate_tabs_to_spaces": true,
"trim_automatic_white_space": true,
"bold_folder_labels": true,
"ensure_newline_at_eof_on_save": true,
"default_line_ending": "unix"
}
}
55 changes: 27 additions & 28 deletions batchy/utils.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
#!/usr/bin/python

import os

from . import FILETYPES


def _list_files(files, dirs):
file_list = []

# get all the files from the CWD
if not files and not dirs:
for r, _, fs in os.walk(os.getcwd()):
files.extend([os.path.join(r, f) for f in fs])

# get all of the files from the given dirs
for d in dirs:
if os.path.isdir(d):
for r, ds, fs in os.walk(d):
files.extend([os.path.join(r, f) for f in fs])

# make sure that the given files are YAML files and exist.
for f in files:
if os.path.isfile(f):
if os.path.splitext(f)[1].strip('.') in FILETYPES:
file_list.append(os.path.relpath(f))

return list(set(file_list))
#!/usr/bin/python

import os

from . import FILETYPES


def _list_files(files, dirs):
def _walk(d):
output = []
if os.path.isdir(d):
for r, _, fs in os.walk(d):
output.extend([os.path.join(r, f) for f in fs])
return output

output = []
# get all the files from the CWD
if not files and not dirs:
output.extend(_walk(os.getcwd()))
else:
# get all of the files from the given dirs
for d in dirs:
output.extend(_walk(d))
# make sure that the given files are YAML files and exist.
output.extend([f for f in files if os.path.isfile(f)])

return list(set([os.path.relpath(f) for f in output if os.path.splitext(f)[1].strip('.') in FILETYPES]))
12 changes: 6 additions & 6 deletions test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def setUp(self):
def tearDown(self):
pass

def test_no_args(self):
def test__cli__no_args(self):
self.assertRaises(SystemExit, main, [])


Expand All @@ -25,10 +25,10 @@ def setUp(self):
def tearDown(self):
pass

def test_no_args(self):
def test__cli__batchy_find__no_args(self):
self.assertRaises(SystemExit, main, ['find'])

def test_no_flags(self):
def test__cli__batchy_find__no_flags(self):
self.assertIs(None, main(['find', 'a']))


Expand All @@ -39,10 +39,10 @@ def setUp(self):
def tearDown(self):
pass

def test_no_args(self):
def test__cli__batchy_update__no_args(self):
self.assertRaises(SystemExit, main, ['update'])

def test_no_flags(self):
def test__cli__batchy_update__no_flags(self):
self.assertIs(None, main(['update', 'a', 'b']))


Expand All @@ -53,5 +53,5 @@ def setUp(self):
def tearDown(self):
pass

def test_no_args(self):
def test__cli__batchy_view__no_args(self):
self.assertIs(None, main(['view']))
109 changes: 61 additions & 48 deletions test/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,61 @@
#!/usr/bin/python

import os
import shutil
import unittest

from . import TESTFILES, TESTDATA, TESTROOT, TESTFILES_ANIMALS, TESTFILES_PEOPLE
from . import setup_file_system, write_file
from batchy.utils import _list_files


class TestListFiles(unittest.TestCase):
@classmethod
def setUpClass(cls):
# setup the test files
cls.cwd = os.getcwd()
os.chdir(os.path.dirname(__file__))
setup_file_system(TESTFILES)

@classmethod
def tearDownClass(cls):
# remove the test files
shutil.rmtree(TESTROOT)
os.chdir(cls.cwd)

def setUp(self):
# make sure that each test starts with the same data
for f, data in TESTDATA.items():
write_file(f, data)

def tearDown(self):
pass

def test__list_files_empty_lists(self):
files = _list_files([], [])
files.sort()
self.assertEqual(files, TESTFILES)

def test__list_files_given_dirs(self):
files = _list_files([], ['files/people'])
files.sort()
self.assertEqual(files, TESTFILES_PEOPLE)

def test__list_files_given_files(self):
focus = ['files/people/bob.yml', 'files/people/jeff.yml']
files = _list_files(focus, [])
files.sort()
self.assertEqual(files, focus)
#!/usr/bin/python

import os
import shutil
import unittest

from . import TESTDATA, TESTROOT
from . import TESTFILES, TESTFILES_ANIMALS, TESTFILES_PEOPLE
from . import setup_file_system, write_file
from batchy.utils import _list_files


class TestListFiles(unittest.TestCase):
@classmethod
def setUpClass(cls):
# setup the test files
cls.cwd = os.getcwd()
os.chdir(os.path.dirname(__file__))
setup_file_system(TESTFILES)

@classmethod
def tearDownClass(cls):
# remove the test files
shutil.rmtree(TESTROOT)
os.chdir(cls.cwd)

def setUp(self):
# make sure that each test starts with the same data
for f, data in TESTDATA.items():
write_file(f, data)

def tearDown(self):
pass

def test__utils__list_files__empty_lists(self):
files = _list_files([], [])
files.sort()
self.assertEqual(files, TESTFILES)

def test__utils__list_files__given_dirs(self):
files = _list_files([], ['files/people'])
files.sort()
self.assertEqual(files, TESTFILES_PEOPLE)

def test__utils__list_files__given_files(self):
focus = ['files/people/bob.yml', 'files/people/jeff.yml']
files = _list_files(focus, [])
files.sort()
self.assertEqual(files, focus)

def test__utils__list_files__given_files_and_dirs(self):
focus = ['files/people/bob.yml', 'files/people/jeff.yml']
output = _list_files(focus, ['files/animals'])
output.sort()
files = focus + TESTFILES_ANIMALS
files.sort()
print TESTFILES_ANIMALS
print files
print output
self.assertEqual(files, output)

0 comments on commit d17cd70

Please sign in to comment.