Beispiel #1
0
 def validate(self, expfile):
     bot.test('EXPERIMENT: %s' % os.path.basename(expfile))
     if expfile.endswith('json'):
         if not self._validate_json(expfile):
             return False
     elif expfile.endswith('md'):
         if not self._validate_markdown(expfile):
             return False
     return True
Beispiel #2
0
 def validate(self, expfile):
     bot.test('EXPERIMENT: %s' % os.path.basename(expfile))
     if expfile.endswith('json'):
         if not self._validate_json(expfile):
             return False
     elif expfile.endswith('md'):
         if not self._validate_markdown(expfile):
             return False
     return True
Beispiel #3
0
 def validate(self, expfile):
     bot.test("EXPERIMENT: %s" % os.path.basename(expfile))
     if expfile.endswith("json"):
         if not self._validate_json(expfile):
             return False
     elif expfile.endswith("md"):
         if not self._validate_markdown(expfile):
             return False
     return True
Beispiel #4
0
 def test_previews(self):
     '''assert that each experiment is previewed at the Github page
        where served
     '''
     bot.test('Testing experiment previews...')
     for jsonfile in self.experiments:
         experiment = os.path.basename(jsonfile)
         print("...%s experiment preview?" % experiment)
         config = read_json(jsonfile)
         self.assertTrue('github' in config)
         self.assertTrue(isinstance(config, dict))
         url = config['github']
         result = self.RuntimeValidator.validate(url)
         print(result)
         print(url)
         self.assertTrue(result)
Beispiel #5
0
    def _validate_preview(self, url):

        bot.test("Experiment url: %s" % url)
        org, repo = url.split("/")[-2:]
        if repo.endswith(".git"):
            repo = repo.replace(".git", "")
        github_pages = "https://%s.github.io/%s" % (org, repo)
        bot.test("Github Pages url: %s" % github_pages)

        response = requests.get(github_pages)

        if response.status_code == 404:
            bot.error("""Preview not found at %s. You must publish a static 
                         preview from the master branch of your repository to
                         add to the library.""" % github_pages)
            return False

        index = response.text
        tmpdir = tempfile.mkdtemp()
        repo_master = clone(url, tmpdir)
        contenders = glob("%s/*" % repo_master)
        license = False
        found = False

        for test in contenders:
            if os.path.isdir(test):
                continue
            print("...%s" % test)
            if "LICENSE" in os.path.basename(test):
                license = True
            if os.path.basename(test) == "index.html":
                bot.test("Found index file in repository.")
                found = True
                break

        if license is False:
            bot.warning(
                "LICENSE file not found. This will be required for future experiments!"
            )

        self._print_valid(found)
        return found
Beispiel #6
0
    def _validate_preview(self, url):

        bot.test('Experiment url: %s' %url)
        org,repo = url.split('/')[-2:]
        if repo.endswith('.git'):
            repo = repo.replace('.git','')
        github_pages =  "https://%s.github.io/%s" %(org,repo)
        bot.test('Github Pages url: %s' %github_pages)

        response = requests.get(github_pages)

        if response.status_code == 404:
            bot.error('''Preview not found at %s. You must publish a static 
                         preview from the master branch of your repository to
                         add to the library.''' % github_pages)
            return False 

        index = response.text
        tmpdir = tempfile.mkdtemp()
        repo_master = clone(url, tmpdir)
        contenders = glob('%s/*' %repo_master)
        license = False
        found = False

        for test in contenders:
            if os.path.isdir(test):
                continue
            print('...%s' %test)
            if "LICENSE" in os.path.basename(test):
                license = True
            if os.path.basename(test) == "index.html":
                bot.test('Found index file in repository.')
                found = True
                break

        if license is False:
            bot.warning("LICENSE file not found. This will be required for future experiments!")

        self._print_valid(found)
        return found
Beispiel #7
0
    def _validate_json(self,jsonfile):
        valids = []
        valid = jsonfile.endswith('.json')
        valids.append(valid)
        bot.test("...extension json: %s" %(self._print_valid(valid))) 

        with open(jsonfile,'r') as filey:
            content = json.load(filey)
        valid = isinstance(content,dict)
        valids.append(valid)
        bot.test("...json loadable: %s" %(self._print_valid(valid)))

        if not all(valids):
            return False

        bot.test("Content:")
        name = os.path.basename(jsonfile)
        exp_id = name.replace('.json','')

        # Validate name
        if "name" not in content:
            return notvalid('"name" not found in %s' % name)

        # Library "name" corresponds to exp_id, name of repo
        if exp_id != content['name']:
            return notvalid('"name" not found in %s' % name)

        bot.test("        Name: %s" % content['name'])

        if not re.match("^[a-z0-9_-]*$", content['name']): 
            return notvalid('''invalid characters in %s, only 
                               lowercase and "-" or "_" allowed.''' %(content['name'])) 
         
        # Validate Github
        if "github" not in content:
            return notvalid('"github" not found in %s' %(name)) 
        if not re.search("(\w+://)(.+@)*([\w\d\.]+)(:[\d]+){0,1}/*(.*)",content['github']):
            return notvalid('%s is not a valid URL.' %(content['github'])) 
        if not isinstance(content["github"],str):
            return notvalid("%s must be a string" %(content['github']))
        bot.test("        Github: %s" % content['github'])

        # Maintainers
        if "maintainer" not in content:
            return notvalid('"maintainer" missing in %s' %(name)) 
        bot.test("        Maintainer: %s" % content['maintainer'])

        return True
Beispiel #8
0
    def _validate_json(self, jsonfile):
        valids = []
        valid = jsonfile.endswith('.json')
        valids.append(valid)
        bot.test("...extension json: %s" % (self._print_valid(valid)))

        with open(jsonfile, 'r') as filey:
            content = json.load(filey)
        valid = isinstance(content, dict)
        valids.append(valid)
        bot.test("...json loadable: %s" % (self._print_valid(valid)))

        if not all(valids):
            return False

        bot.test("Content:")
        name = os.path.basename(jsonfile)
        exp_id = name.replace('.json', '')

        # Validate name
        if "name" not in content:
            return notvalid('"name" not found in %s' % name)

        # Library "name" corresponds to exp_id, name of repo
        if exp_id != content['name']:
            return notvalid('"name" not found in %s' % name)

        bot.test("        Name: %s" % content['name'])

        if not re.match("^[a-z0-9_-]*$", content['name']):
            return notvalid('''invalid characters in %s, only 
                               lowercase and "-" or "_" allowed.''' %
                            (content['name']))

        # Validate Github
        if "github" not in content:
            return notvalid('"github" not found in %s' % (name))
        if not re.search("(\w+://)(.+@)*([\w\d\.]+)(:[\d]+){0,1}/*(.*)",
                         content['github']):
            return notvalid('%s is not a valid URL.' % (content['github']))
        if not isinstance(content["github"], str):
            return notvalid("%s must be a string" % (content['github']))
        bot.test("        Github: %s" % content['github'])

        # Maintainers
        if "maintainer" not in content:
            return notvalid('"maintainer" missing in %s' % (name))
        bot.test("        Maintainer: %s" % content['maintainer'])

        return True