def _check_directory(self, listname, thing_list, thing_dir, thing_key, ignore=None):
        if ignore is None:
            ignore = []
        dirs = testing_utils.git_ls_dirs()
        # get only directories directly in the thing directory
        dirs = [d for d in dirs if os.path.dirname(d) == thing_dir]
        # just the folder names
        dirs = [os.path.basename(d) for d in dirs]
        # skip the whitelist
        dirs = [d for d in dirs if d not in ignore]
        # make it a set
        dirs = set(dirs)

        # and the list of thing names
        thing_names = {thing[thing_key].split(':')[0] for thing in thing_list}

        errors = []
        # items with a directory but not a listing
        for name in dirs - thing_names:
            errors.append(
                "Directory {}/{} exists, but isn't in {}".format(
                    thing_dir, name, listname
                )
            )
        for name in thing_names - dirs:
            errors.append(
                "{} exists in {}, but {}/{} isn't a directory".format(
                    name, listname, thing_dir, name
                )
            )

        if errors:
            self.assertTrue(False, "\n".join(errors))
Example #2
0
 def test_init_everywhere(self):
     for folder in testing_utils.git_ls_dirs('parlai'):
         if 'mturk' in folder:
             continue
         self.assertIn(
             '__init__.py',
             os.listdir(folder),
             '{} does not contain __init__.py'.format(folder),
         )