def test_traverse(): res = [t for t in traverse.scan(data_path) if t['slug'] == 'protocol1'] del res[0]['containers'] del res[0]['instruments'] expected = [{ 'slug': 'protocol1', 'path': os.path.join(data_path, 'protocol1'), 'files': { 'OT 1 protocol': 'protocol.ot1.py', 'OT 2 protocol': None, 'description': 'README.md' }, 'detected-files': { 'OT 1 protocol': ['protocol.ot1.py'], 'OT 2 protocol': [], 'description': ['README.md'] }, 'flags': { 'ignore': False, 'skip-tests': False, 'feature': True, 'embedded-app': False }, 'status': 'ok', 'errors': [], 'markdown': {}, 'parameters': [] }] assert res == expected
def test_protocol_ignore(): res = [ p for p in traverse.scan_for_protocols(data_path) if p['flags']['ignore'] ] expected = [{ 'slug': 'protocol3', 'path': os.path.join(data_path, 'protocol3'), 'detected-files': { 'OT 1 protocol': ['protocol.ot1.py'], 'OT 2 protocol': ['protocol.ot2.py'], 'description': ['README.md'], }, 'flags': { 'ignore': True, 'feature': False, 'skip-tests': False, 'embedded-app': False }, }] assert res == expected found_protocols = [p for p in traverse.scan(data_path)] slugs = [p['slug'] for p in found_protocols] assert not any(['protocol3' in s for s in slugs])
def test_missing_md(): res = [ t for t in traverse.scan(data_path) if (t['slug'] == 'category1/protocol2') # this is missing md fixture ] del res[0]['containers'] del res[0]['instruments'] expected = [{ 'slug': 'category1/protocol2', 'path': os.path.join(data_path, 'category1/protocol2'), 'status': 'error', 'files': { 'description': None, 'OT 1 protocol': 'protocol.ot1.py', 'OT 2 protocol': 'protocol.ot2.py' }, 'detected-files': { 'description': [], 'OT 1 protocol': ['protocol.ot1.py'], 'OT 2 protocol': ['protocol.ot2.py'] }, 'flags': { 'ignore': False, 'skip-tests': False, 'feature': False, 'embedded-app': False }, 'errors': ['Found 0 description files required 1'], 'parameters': [] }] assert res == expected
def test_missing_py(): res = [ t for t in traverse.scan(data_path) if (t['status'] == 'error' and t['errors'] == ['Found 0 protocol files required at least 1']) ] expected = [{ 'slug': 'category1/protocol1', 'path': os.path.join(data_path, 'category1/protocol1'), 'status': 'error', 'files': { 'description': 'README.md', 'OT 1 protocol': None, 'OT 2 protocol': None }, 'detected-files': { 'description': ['README.md'], 'OT 1 protocol': [], 'OT 2 protocol': [] }, 'flags': { 'ignore': False, 'skip-tests': False, 'feature': False, 'embedded-app': False }, 'errors': ['Found 0 protocol files required at least 1'], 'markdown': {} }, { 'slug': 'protocolApp', 'path': os.path.join(data_path, 'protocolApp'), 'flags': { 'ignore': False, 'feature': False, 'skip-tests': False, 'embedded-app': 'http://blah.aws.s3/something/app.html' }, 'files': { 'description': 'README.md', 'OT 1 protocol': None, 'OT 2 protocol': None }, 'detected-files': { 'description': ['README.md'], 'OT 1 protocol': [], 'OT 2 protocol': [] }, 'status': 'error', 'errors': ['Found 0 protocol files required at least 1'], 'markdown': {} }] assert res == expected
def build_protocol_library(): parser = configure_parser() parsed_input = parser.parse_args() PROTOCOLS_BUILD_DIR = os.path.join(tempfile.gettempdir(), 'proto-builds') PROTOCOLS_RELEASE_DIR = parsed_input.library_output_path print('preparing build & release dirs...') prepare_dirs( PROTOCOLS_BUILD_DIR, PROTOCOLS_RELEASE_DIR, parsed_input.library_input_path ) build_name = utils.get_build_name() build_name = "PL-data-{}".format(build_name) print('build_name is:', build_name) def get_file_name(name, ext): return "{name}{ext}".format(name=name, ext=ext) if parsed_input.fake: protocols_json_data = list(generate.generate(parsed_input.amt)) else: protocols_json_data = traverse.scan(parsed_input.library_input_path) # Persist protocol data def persist_data(data, file_name): json_path = os.path.join( PROTOCOLS_BUILD_DIR, get_file_name(file_name, '.json') ) persist.write_json_to_file(data, json_path) return json_path print('traversing categories...') protocols_json_data = { 'categories': traverse.tree(protocols_json_data), 'protocols': protocols_json_data } print('persisting protocol data...') protocols_path = persist_data(protocols_json_data, build_name) utils.zip_file( [protocols_path], os.path.join(PROTOCOLS_RELEASE_DIR, get_file_name(build_name, '.zip')) ) print('Successfully built library')