class TestContribution(TestCase): def setUp(self): self.LibValidator = LibraryValidator() self.ExpValidator = ExperimentValidator() self.RuntimeValidator = RuntimeValidator() self.experiments_base = "/scif/data" self.experiments = glob("%s/*md" % self.experiments_base) def test_contribution(self): '''test an experiment, including the markdown file, and repo itself ''' if len(self.experiments) == 0: print( 'Please bind the directory with your markdown files for the library.' ) sys.exit(1) print("...Test: Global Library validation") for ymlfile in self.experiments: self.assertTrue(self.LibValidator.validate(ymlfile)) url = self.LibValidator.metadata['github'] self.assertTrue(self.ExpValidator.validate(url)) result = self.RuntimeValidator.validate(url) print(result) print(url) self.assertTrue(result)
class TestContribution(TestCase): def setUp(self): self.LibValidator = LibraryValidator() self.ExpValidator = ExperimentValidator() self.RuntimeValidator = RuntimeValidator() self.experiments_base = "/scif/data" self.experiments = glob("%s/*md" %self.experiments_base) def test_contribution(self): '''test an experiment, including the markdown file, and repo itself ''' if len(self.experiments) == 0: print('Please bind the directory with your markdown files for the library.') sys.exit(1) print("...Test: Global Library validation") for ymlfile in self.experiments: self.assertTrue(self.LibValidator.validate(ymlfile)) url = self.LibValidator.metadata['github'] self.assertTrue(self.ExpValidator.validate(url)) result = self.RuntimeValidator.validate(url) print(result) print(url) self.assertTrue(result)
class TestLibrary(TestCase): def setUp(self): self.LibValidator = LibraryValidator() self.ExpValidator = ExperimentValidator() self.RuntimeValidator = RuntimeValidator() self.experiments_base = "%s/docs/_library" % (here) self.experiments = self.get_changed_files() self.added = [x for x in self.experiments if '_library' in x] print('Found %s changed or modified files.' % len(self.added)) def get_changed_files(self): '''use the Github compare url (provided by circle) to find changed files between commits''' # Fallback, return all files in experiment base experiments = glob("%s/*" % self.experiments_base) compare_url = os.environ.get("CIRCLE_COMPARE_URL") # If the variable exists, we are running on Circle if compare_url is not None: print('Detected running in Circle CI') # If defined, derive change list from compare url if compare_url != '': compare_url = "%s.patch" % compare_url print("Compare URL: %s" % compare_url) response = requests.get(compare_url) if response.status_code == 200: experiments = set( re.findall(' docs/_library/.+[.]md', response.text)) experiments = [x.strip() for x in experiments] # Otherwise, use all experiments else: print("No compare URL detected, using entire listing.") experiments = glob('%s/*.md' % self.experiments_base) else: print("Not running in Circle Ci") return experiments def test_experiment(self): '''test an experiment, including the markdown file, and repo itself ''' print("...Test: Global Library validation") for ymlfile in self.experiments: if os.path.exists(ymlfile): print("TESTING %s" % ymlfile) self.assertTrue(self.LibValidator.validate(ymlfile)) url = self.LibValidator.metadata['github'] self.assertTrue(self.ExpValidator.validate(url)) result = self.RuntimeValidator.validate(url) print(result) print(url) self.assertTrue(result)
class TestLibrary(TestCase): def setUp(self): self.LibValidator = LibraryValidator() self.ExpValidator = ExperimentValidator() self.RuntimeValidator = RuntimeValidator() self.experiments_base = "%s/experiments" % (here) self.experiments = glob("%s/*" % self.experiments_base) def test_library(self): '''test_validate_library calls all subfunctions ''' print("...Test: Global Library validation") for jsonfile in self.experiments: self.assertTrue(self.LibValidator.validate(jsonfile)) def test_single_experiments(self): '''test_load_json ensures that all files load ''' for jsonfile in self.experiments: print("...%s" % os.path.basename(jsonfile)) config = read_json(jsonfile) self.assertTrue('github' in config) self.assertTrue(isinstance(config, dict)) url = config['github'] self.assertTrue(self.ExpValidator.validate(url)) 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)
from glob import glob import os import re import sys import json from expfactory.validator import LibraryValidator from expfactory.utils import write_json here = os.getcwd() experiments_base = "%s/experiments" % (here) experiments_url = "https://expfactory.github.io/library/experiments" experiments = glob("%s/*" % experiments_base) output_file = "%s/index.json" % (here) if len(sys.argv) > 1: output_file = sys.argv[1] validator = LibraryValidator() final_set = [] for experiment in experiments: if validator.validate(experiment): with open(experiment) as filey: content = json.loads(filey.read()) content['metadata'] = "%s/%s.json" % (experiments_url, content['name']) final_set.append(content) write_json(final_set, output_file)