Example #1
0
 def _create_sample_file(self, *lines):
     """General abstraction to be used with the -f commands.
     Keep in mind that you need to delete the created file,
     just to be cleaner.
     """
     if not lines:
         lines = (self.sample_mac, )
     return _test_utils.create_sample_file(*lines)
Example #2
0
 def test__split_file(self):
     separators = ['|', '%', '!', '*', ':', ',', '\n']
     for separator in separators:
         lines = []
         for letter in string.ascii_letters:
             line = letter * 10
             lines.append(line)
         fpath = _test_utils.create_sample_file(separator.join(lines))
         try:
             self.assertEqual(utils._split_file(fpath, separator),
                              lines)
         finally:
             os.remove(fpath)
Example #3
0
 def test_fetch_macs_from_file(self):
     
     slines = ['11.11.11.11.11 # one',
               '22.11.11.11.11 # two',
               'Invalid mac # thats ok',
               '# line with comment']
     
     expmacs = ['11.11.11.11.11',
                '22.11.11.11.11',
                'Invalid mac']
     separators = [':', '*', '!', '\n']
     for sep in separators:
         sfile = _test_utils.create_sample_file(sep.join(slines))
         try:
             for mac in utils.fetch_macs_from_file(sfile, '\n'):
                 self.assertIn(mac, expmacs)
         finally:
             os.remove(sfile)