예제 #1
0
 def test_json_parse(self):
     protocol = Protocol()
     with open('test/manifest_test.json', 'r') as f:
         manifest_json = f.read()
         manifest = Manifest(json.loads(manifest_json))
         source = json.loads(manifest_json)['protocols'][0]['preview']
         manifest.protocol_info('TestMethod').parse(protocol, source)
예제 #2
0
 def test_json_parse(self):
     protocol = Protocol()
     with open('test/manifest_test.json', 'r') as f:
         manifest_json = f.read()
         manifest = Manifest(json.loads(manifest_json))
         source = json.loads(manifest_json)['protocols'][0]['preview']
         manifest.protocol_info('TestMethod').parse(protocol, source)
 def test_json_parse(self):
     with open("test/manifest_test.json", "r") as f:
         manifest_json = f.read()
         manifest = Manifest(json.loads(manifest_json))
         source = json.loads(manifest_json)["protocols"][0]["preview"]
         manifest.protocol_info("TestMethod").parse(self.protocol, source)
 def test_json_parse(self):
     protocol = Protocol()
     manifest_json = open("test/manifest_test.json", "r").read().decode("utf-8")
     manifest = Manifest(json.loads(manifest_json))
     source = json.loads(manifest_json)["protocols"][0]["preview"]
     params = manifest.protocol_info("TestMethod").parse(protocol, source)
예제 #5
0
def run(
        fn,
        protocol_name=None,
        seal_after_run=True,
        #this is new to allow testing
        config=None):
    """
    Run the protocol specified by the function.

    If protocol_name is passed, use preview parameters from the protocol with
    the matching "name" value in the manifest.json file to run the given
    function.  Otherwise, take configuration JSON file from the command line
    and run the given function.

    Parameters
    ----------
    fn : function
        Function that generates Autoprotocol
    protocol_name :  str, optional
        str matching the "name" value in the manifest.json file
    seal_after_run : bool, optional
        Implicitly add a seal/cover to all stored refs within the protocol
        using seal_on_store()
    """
    #new to allow config
    if not config:
        parser = argparse.ArgumentParser()
        parser.add_argument('config',
                            help='JSON-formatted protocol configuration file')
        args = parser.parse_args()
        #new
        config = args.config

    source = json.loads(io.open(config, encoding='utf-8').read())
    protocol = Protocol()
    if protocol_name:
        manifest_json = io.open('manifest.json', encoding='utf-8').read()
        manifest = Manifest(json.loads(manifest_json))

        # ---- This block is custom to dtx -----

        if not source:
            print(io.open('fake_protocol.json', encoding='utf-8').read())
            return

        # ------End of custom block ------

        params = manifest.protocol_info(protocol_name).parse(protocol, source)
    else:
        params = protocol._ref_containers_and_wells(source["parameters"])

    #----- This block is custom to dtx -----

    protocol.set_test_mode(params.get("test_mode", True))
    #protocol.init_all_refs()

    #----- End of New Block ------

    try:
        fn(protocol, params)
        if seal_after_run:
            seal_on_store(protocol)

        #---- This block is custom to dtx -----

        protocol.assert_valid_state()

        #---- End of New Block -------

    except UserError as e:
        print(
            json.dumps({'errors': [{
                'message': e.message,
                'info': e.info
            }]},
                       indent=2))
        return
    #----- This block is custom to dtx -----
    except:
        e = sys.exc_info()[1]

        additional_information = '\n'+'*'*50+\
            '\n inputs were %s\n'%json.dumps(source,
                                             indent=4)\
            +'*'*50+'\n'
        print(additional_information, file=sys.stderr)
        #aise type(e), e.message, sys.exc_info()[2]
        raise

    #----- End of New Block ------

    print(json.dumps(protocol.as_dict(), indent=2))