Ejemplo n.º 1
0
 def do(self):
     path = self.path
     if not path or not os.path.isfile(path):
         raise errors.UsageError('Error: cannot find commit template',
                                 '%s: No such file or directory.' % path)
     self.model.set_directory(os.path.dirname(path))
     self.model.set_commitmsg(utils.slurp(path))
Ejemplo n.º 2
0
 def test_slurp_ioerror(self):
     with mock.patch('builtins.open', mock.mock_open()) as mock_open:
         with mock.patch('sys.stderr', new=StringIO()) as mock_err:
             mock_open.side_effect = IOError()
             pbar = mock.MagicMock()
             list(slurp(Path('foo_filename'), pbar))
             pbar.update.assert_not_called()
             self.assertIn('foo_filename', mock_err.getvalue())
Ejemplo n.º 3
0
 def do(self):
     new_additions = ''
     for fname in self.filenames:
         new_additions = new_additions + fname + '\n'
     for_status = new_additions
     if new_additions:
         if os.path.exists('.gitignore'):
             current_list = utils.slurp('.gitignore')
             new_additions = new_additions + current_list
         utils.write('.gitignore', new_additions)
         _notifier.broadcast(signals.log_cmd,
                             0,
                             'Added to .gitignore:\n%s' % for_status)
         self.model.update_file_status()
Ejemplo n.º 4
0
from sys import argv
from BeautifulSoup import BeautifulSoup
from utils import slurp

old = slurp(argv[1])
print BeautifulSoup(old)
Ejemplo n.º 5
0
 def assert_slurp_correct(self, data: bytes, kwargs: dict, pbar_update_calls: list):
     with mock.patch('builtins.open', mock.mock_open(read_data=data)) as mock_open:
         pbar = mock.MagicMock()
         self.assertEqual(data, b''.join(slurp(Path('foo_filename'), pbar, **kwargs)))
         mock_open.assert_called_once_with(Path('foo_filename'), 'rb')
         self.assertEqual(pbar_update_calls, pbar.update.mock_calls)
Ejemplo n.º 6
0
 def inputFile(self, filePath):
     self.lexer.input(slurp(filePath))
Ejemplo n.º 7
0
from sys import argv
from utils import slurp

if argv[1] == 'difflib':
  import difflib
  s = difflib.SequenceMatcher(a=slurp(argv[2]), b=slurp(argv[3]))
  print s.get_matching_blocks()

elif argv[1] == 'dmp':
  from diff_match_patch import diff_match_patch
  s = diff_match_patch()
  print [[x[0], len(x[1])] for x in s.diff_main(slurp(argv[2]), slurp(argv[3]))]
Ejemplo n.º 8
0
t_NROFSUBSUBTESTS = r"[ ]+1\.\.[0-9]+\n"

t_OK = r"ok[ ][0-9]+([ ]-[ ][\w ]+\n|\n|[ ][#].*\n)"

t_OKSUB = r"[ ][ ][ ][ ]ok[ ][0-9]+([ ]-[ ][\w ]+\n|\n|[ ][#].*\n)"

t_OKSUBSUB = r"[ ][ ][ ][ ][ ][ ][ ][ ]ok[ ][0-9]+([ ]-[ ][\w ]+\n|\n|[ ][#].*\n)"

t_NOTOK = r"not[ ]ok[ ][0-9]+([ ]-[ ][\w ]+\n|\n|[ ][#].*\n)"

t_NOTOKSUB = r"[ ][ ][ ][ ]not[ ]ok[ ][0-9]+([ ]-[ ][\w ]+\n|\n|[ ][#].*\n)"

t_NOTOKSUBSUB = r"[ ][ ][ ][ ][ ][ ][ ][ ]not[ ]ok[ ][0-9]+([ ]-[ ][\w ]+\n|\n|[ ][#].*\n)"

t_COMMENTS = r"[ ]+[#].*\n|([#].*\n)"







def t_error(t):
    print("error [%s]" % t.value)
    exit(1)

lexer = lex.lex()
lexer.input(slurp("teste3.t"))
for token in iter(lexer.token, None):
    print(token)