def testWithEnvThenWithoutEnv(self): """ This test shows that if you create the config using an env setting, then without, the __ACTIVE__ block should reflect "default" and not the intermediate "env" setting. """ def get_profile_name(p): """ Takes a path object to the config xml """ xml = XML(p.text()) props = xml.findall("./properties") for x in props: id = x.attrib["id"] if id == "__ACTIVE__": for y in x.getchildren(): if y.attrib["name"] == "omero.config.profile": return y.attrib["value"] p = create_path() current = os.environ.get("OMERO_CONFIG", "default") assert current != "FOO" # Just in case. config = ConfigXml(filename=str(p)) config.close() assert current == get_profile_name(p) config = ConfigXml(filename=str(p), env_config="FOO") config.close() assert "FOO" == get_profile_name(p) # Still foo config = ConfigXml(filename=str(p)) config.close() assert "FOO" == get_profile_name(p) # Re-setting with os.environ won't work try: old = os.environ.get("OMERO_CONFIG", None) os.environ["OMERO_CONFIG"] = "ABC" config = ConfigXml(filename=str(p)) config.close() assert "FOO" == get_profile_name(p) finally: if old is None: del os.environ["OMERO_CONFIG"] else: os.environ["OMERO_CONFIG"] = old # But we can reset it with env_config config = ConfigXml(filename=str(p), env_config="ABC") config.close() assert "ABC" == get_profile_name(p) # or manually. ticket:7343 config = ConfigXml(filename=str(p)) config.default("XYZ") config.close() assert "XYZ" == get_profile_name(p)
def testLoadTagset(self, capfd): ts_name = self.uuid() ts_desc = self.uuid() tag_names = ["tagset %s - %s" % (ts_name, x) for x in [1, 2]] p = create_path(suffix=".json") p.write_text(""" [{ "name" : "%s", "desc" : "%s", "set" : [{ "name" : "%s", "desc" : ""}, { "name" : "%s", "desc" : ""}] }]""" % (ts_name, ts_desc, tag_names[0], tag_names[1])) self.args += ["load", str(p)] self.cli.invoke(self.args, strict=True) o, e = capfd.readouterr() # Check tagset is created tagset = self.get_object(o) assert tagset.textValue.val == ts_name assert tagset.ns.val == NSINSIGHTTAGSET assert tagset.description.val == ts_desc # Check all tags are linked to the tagset tags = self.get_tags_in_tagset(tagset.id.val) assert sorted([x.textValue.val for x in tags]) == sorted(tag_names)
def create_script(self): path = create_path() for x in ("Screen", "Plate", "Project", "Dataset"): path.write_text("new %s name=test\n" % x, append=True) path.write_text("new %s name=test description=foo\n" % x, append=True) return path
def run(self, args): if not os.path.exists(args.file): self.ctx.die(670, "No such file: %s" % args.file) else: client = self.ctx.conn(args) store = SessionsStore() srv, usr, uuid = store.get_current() props = store.get(srv, usr, uuid) from omero.scripts import parse_file from omero.util.temp_files import create_path path = create_path() text = """ omero.host=%(omero.host)s omero.user=%(omero.sess)s omero.pass=%(omero.sess)s """ path.write_text(text % props) params = parse_file(args.file) m = self._parse_inputs(args, params) for k, v in m.items(): if v is not None: client.setInput(k, v) p = self.ctx.popen([sys.executable, args.file], stdout=sys.stdout, stderr=sys.stderr, ICE_CONFIG=str(path)) p.wait() if p.poll() != 0: self.ctx.die(p.poll(), "Execution failed.")
def testCannotCreate(self): d = create_path(folder=True) d.chmod(0555) filename = str(d / "config.xml") with pytest.raises(IOError) as excinfo: ConfigXml(filename).close() assert excinfo.value.errno == errno.EACCES
def setup_method(self, method): # Non-temp directories build_dir = path() / "build" top_dir = path() / ".." / ".." / ".." etc_dir = top_dir / "etc" # Necessary fiels prefs_file = build_dir / "prefs.class" internal_cfg = etc_dir / "internal.cfg" master_cfg = etc_dir / "master.cfg" # Temp directories tmp_dir = create_path(folder=True) tmp_etc_dir = tmp_dir / "etc" tmp_grid_dir = tmp_etc_dir / "grid" tmp_lib_dir = tmp_dir / "lib" tmp_var_dir = tmp_dir / "var" # Setup tmp dir [x.makedirs() for x in (tmp_grid_dir, tmp_lib_dir, tmp_var_dir)] prefs_file.copy(tmp_lib_dir) master_cfg.copy(tmp_etc_dir) internal_cfg.copy(tmp_etc_dir) # Other setup self.cli = MockCLI() self.cli.dir = tmp_dir self.cli.register("admin", AdminControl, "TEST") self.cli.register("config", PrefsControl, "TEST")
def testImport(self): import time s1 = time.time() client = self.new_client() mrepo = self.getManagedRepo(client) folder = create_path(folder=True) for x in range(200): name = "%s.unknown" % x (folder / name).touch() paths = folder.files() proc = mrepo.importPaths(paths) hashes = self.upload_folder(proc, folder) handle = proc.verifyUpload(hashes) req = handle.getRequest() fs = req.activity.getParent() cb = CmdCallbackI(client, handle) self.assertError(cb, loops=200) delete = omero.cmd.Delete2() delete.targetObjects = {'Fileset': [fs.id.val]} s2 = time.time() print s2 - s1, t1 = time.time() client.submit(delete, loops=200) t2 = time.time() print " ", t2-t1,
def test421Upgrade(self): """ When upgraded 4.2.0 properties to 4.2.1, ${dn} items in omero.ldap.* properties are changed to @{dn} """ p = create_path() # How config was written in 4.2.0 XML = Element("icegrid") active = SubElement(XML, "properties", id="__ACTIVE__") default = SubElement(XML, "properties", id="default") for properties in (active, default): SubElement( properties, "property", name="omero.config.version", value="4.2.0") SubElement( properties, "property", name="omero.ldap.new_user_group", value="member=${dn}") SubElement( properties, "property", name="omero.ldap.new_user_group_2", value="member=$${omero.dollar}{dn}") string = tostring(XML, 'utf-8') txt = xml.dom.minidom.parseString(string).toprettyxml(" ", "\n", None) p.write_text(txt) config = ConfigXml(filename=str(p), env_config="default") try: m = config.as_map() assert "member=@{dn}" == m["omero.ldap.new_user_group"] assert "member=@{dn}" == m["omero.ldap.new_user_group_2"] finally: config.close()
def testAutoFillTicket2326(self): SCRIPT = """if True: import omero.scripts import omero.rtypes client = omero.scripts.client("ticket2326", omero.scripts.Long("width", optional=True)) width = client.getInput("width") print width client.setOutput("noWidthKey", omero.rtypes.rbool("width" not in client.getInputKeys())) client.setOutput("widthIsNull", omero.rtypes.rbool(width is None)) """ impl = omero.processor.usermode_processor(self.client) svc = self.client.sf.getScriptService() try: scriptID = svc.uploadScript("/test/testAutoFillTicket2326", SCRIPT) process = svc.runScript(scriptID, {}, None) cb = omero.scripts.ProcessCallbackI(self.client, process) while cb.block(500) is None: pass results = process.getResults(0) stdout = results["stdout"].val downloaded = create_path() self.client.download(ofile=stdout, filename=str(downloaded)) text = downloaded.text().strip() self.assertEquals("None", text) self.assertTrue(results["widthIsNull"].val) self.assertTrue(results["noWidthKey"].val) self.assertTrue("stderr" not in results) finally: impl.cleanup()
def demo(self, args): from omero.util.temp_files import create_path t = create_path("Demo_Script", ".py") try: from hashlib import sha1 as sha_new except ImportError: from sha import new as sha_new digest = sha_new() digest.update(DEMO_SCRIPT) sha1 = digest.hexdigest() self.ctx.out("\nExample script writing session") self.ctx.out("="*80) def msg(title, method=None, *arguments): self.ctx.out("\n") self.ctx.out("\t+" + ("-"*68) + "+") title = "\t| %-66.66s | " % title self.ctx.out(title) if method: cmd = "%s %s" % (method.__name__, " ".join(arguments)) cmd = "\t| COMMAND: bin/omero script %-40.40s | " % cmd self.ctx.out(cmd) self.ctx.out("\t+" + ("-"*68) + "+") self.ctx.out(" ") if method: try: self.ctx.invoke(['script', method.__name__] + list(arguments)) except Exception, e: import traceback self.ctx.out("\nEXECUTION FAILED: %s" % e) self.ctx.dbg(traceback.format_exc())
def testWithEnvThenWithoutEnv(self): """ This test shows that if you create the config using an env setting, then without, the __ACTIVE__ block should reflect "default" and not the intermediate "env" setting. """ def get_profile_name(p): """ Takes a path object to the config xml """ xml = XML(p.text()) props = xml.findall("./properties") for x in props: id = x.attrib["id"] if id == "__ACTIVE__": for y in x.getchildren(): if y.attrib["name"] == "omero.config.profile": return y.attrib["value"] p = create_path() current = os.environ.get("OMERO_CONFIG", "default") config = ConfigXml(filename=str(p)) config.close() self.assertEquals(current, get_profile_name(p)) config = ConfigXml(filename=str(p), env_config="FOO") config.close() self.assertEquals("FOO", get_profile_name(p)) config = ConfigXml(filename=str(p)) config.close() self.assertEquals(current, get_profile_name(p))
def setup_method(self, method): # # Non-temp directories ctxdir = path() / ".." / ".." / ".." / "dist" etc_dir = ctxdir / "etc" # List configuration files to backup self.cfg_files = {} for f in ['internal.cfg', 'master.cfg', 'ice.config']: self.cfg_files[f] = etc_dir / f for f in ['windefault.xml', 'default.xml', 'config.xml']: self.cfg_files[f] = etc_dir / 'grid' / f # Create temp files for backup tmp_dir = create_path(folder=True) self.tmp_cfg_files = {} for key in self.cfg_files.keys(): if self.cfg_files[key].exists(): self.tmp_cfg_files[key] = tmp_dir / key self.cfg_files[key].copy(self.tmp_cfg_files[key]) else: self.tmp_cfg_files[key] = None # Other setup self.cli = CLI() self.cli.dir = ctxdir self.cli.register("admin", AdminControl, "TEST") self.args = ["admin", "ports"]
def setup_method(self, method): self.cli = CLI() self.cli.register("db", DatabaseControl, "TEST") dir = path(__file__) / ".." / ".." / ".." / ".." / ".." / ".." /\ ".." / "dist" # FIXME: should not be hard-coded dir = dir.abspath() cfg = dir / "etc" / "omero.properties" cfg = cfg.abspath() self.cli.dir = dir self.data = {} for line in cfg.text().split("\n"): line = line.strip() for x in ("version", "patch"): key = "omero.db." + x if line.startswith(key): self.data[x] = line[len(key)+1:] self.file = create_path() self.script_file = "%(version)s__%(patch)s.sql" % self.data if os.path.isfile(self.script_file): os.rename(self.script_file, self.script_file + '.bak') assert not os.path.isfile(self.script_file) self.mox = Mox() self.mox.StubOutWithMock(getpass, 'getpass') self.mox.StubOutWithMock(__builtin__, "raw_input")
def test_get_unit_and_value(self): # units defaults to MICROMETER fake = create_path("image", "&physicalSizeX=1.0.fake") pixIds = self.import_image(filename=fake.abspath()) self.args = self.login_args() + [ "obj", "get", "Pixels:%s" % pixIds[0], "physicalSizeX"] state = self.go() assert state.get_row(0) == "1.0 MICROMETER"
def prep_directory(client, mrepo): """ Create an empty FS directory by performing an import and then deleting the created fileset. """ from omero.cmd import Delete2, DoAll from omero.grid import ImportSettings from omero.model import ChecksumAlgorithmI from omero.model import FilesetI from omero.model import FilesetEntryI from omero.model import UploadJobI fs = FilesetI() fs.linkJob(UploadJobI()) entry = FilesetEntryI() entry.clientPath = rstring("README.txt") fs.addFilesetEntry(entry) settings = ImportSettings() settings.checksumAlgorithm = ChecksumAlgorithmI() settings.checksumAlgorithm.value = rstring("SHA1-160") proc = mrepo.importFileset(fs, settings) try: tmp = create_path() prx = proc.getUploader(0) try: tmp.write_text("THIS IS A PLACEHOLDER") hash = client.sha1(tmp) with open(tmp, "r") as source: client.write_stream(source, prx) finally: prx.close() tmp.remove() handle = proc.verifyUpload([hash]) try: req = handle.getRequest() fs = req.activity.parent finally: handle.close() dir = unwrap(mrepo.treeList(fs.templatePrefix.val)) oid = dir.items()[0][1].get("id") ofile = client.sf.getQueryService().get("OriginalFile", oid) delete1 = Delete2(targetObjects={"Fileset": [fs.id.val]}) delete2 = Delete2(targetObjects={"OriginalFile": [ofile.id.val]}) doall = DoAll() doall.requests = [delete1, delete2] cb = client.submit(doall) cb.close(True) finally: proc.close() return fs.templatePrefix.val
def preMethod(self): self.dir = create_path("bin_test", folder=True) self.bin = self.dir / "bin" self.bin.makedirs() self.omero = self.bin / "omero" self.omero.write_text( orig.text() ) self.exe = """sh -c "python '%s' '' " """ % self.omero.abspath() self.mkdir = """sudo sh -c "mkdir '%s/var'" """ % self.dir.abspath() # Always sudo self.chmod = """sudo sh -c "chmod %%s '%s/var'" """ % self.dir.abspath() # "
def __init__(self, *args, **kwargs): CLI.__init__(self, *args, **kwargs) self.DIR = create_path(folder=True) self.REQRESP = {} self.STORE = MyStore(self.DIR) self.STORE.clear(testhost, testuser) self.register("s", SessionsControl, "TEST") self.controls["s"].FACTORY = lambda ignore: self.STORE assert self.STORE.count(testhost, testuser) == 0
def setUp(self): self.cli = MockCLI() self.cli.register("db", DatabaseControl, "TEST") db = self.cli.controls["db"] data = db.loaddefaults() self.data = {} for x in ("version", "patch"): self.data[x] = data.properties.getProperty("omero.db."+x) self.file = create_path()
def testLocking(self): p = create_path() config1 = ConfigXml(filename=str(p)) try: config2 = ConfigXml(filename=str(p)) self.fail("No exception") except portalocker.LockException: pass config1.close()
def testNewVersioning(self): """ All property blocks should always have a version set. """ p = create_path() config = ConfigXml(filename=str(p)) m = config.as_map() for k, v in list(m.items()): assert "5.1.0" == v
def testLocking(self): p = create_path() config1 = ConfigXml(filename=str(p)) try: ConfigXml(filename=str(p)) assert False, "No exception" except portalocker.LockException: pass config1.close()
def setUp(self): self.cli = MockCLI() self.cli.register("db", DatabaseControl, "TEST") db = self.cli.controls["db"] data = db.loaddefaults() self.data = {} for x in ("version", "patch"): self.data[x] = data.properties.getProperty("omero.db." + x) self.file = create_path()
def testNewVersioning(self): """ All property blocks should always have a version set. """ p = create_path() config = ConfigXml(filename=str(p)) m = config.as_map() for k, v in m.items(): self.assertEquals("4.2.1", v)
def pingfile(self): pingfile = create_path() pingfile.write_text("""if True: import omero import omero.scripts as OS import omero.grid as OG OS.client("ping-%s") """ % self.uuid()) return pingfile
def test_upload_multiple_files(self, capfd, ln_s): f1 = create_path(suffix=".txt") f2 = create_path(suffix=".txt") self.args += [str(f1), str(f2)] if ln_s: self.args += ["--data-dir", "/OMERO"] out = self.upload(capfd) assert out.startswith("OriginalFile:") objects = self.get_objects(out) assert len(objects) == 2 assert objects[0].name.val == f1.name assert objects[1].name.val == f2.name if ln_s: assert self.is_symlink(objects[0]) assert self.is_symlink(objects[1]) else: assert not self.is_symlink(objects[0]) assert not self.is_symlink(objects[1])
def testNewVersioning(self): """ All property blocks should always have a version set. """ p = create_path() config = ConfigXml(filename=str(p)) m = config.as_map() for k, v in m.items(): assert "5.1.0" == v
def test_guessed_mimetype(self, capfd): f = create_path(suffix=".txt") self.args += [str(f)] out = self.upload(capfd) assert out.startswith("OriginalFile:") objects = self.get_objects(out) assert len(objects) == 1 assert objects[0].name.val == f.name assert objects[0].mimetype.val == "text/plain"
def edit(self, args, config, edit_path = edit_path): from omero.util.temp_files import create_path, remove_path start_text = "# Edit your preferences below. Comments are ignored\n" for k in sorted(config.keys()): start_text += ("%s=%s\n" % (k, config[k])) temp_file = create_path() try: edit_path(temp_file, start_text) except RuntimeError, re: self.ctx.die(954, "%s: Failed to edit %s" % (getattr(re, "pid", "Unknown"), temp_file))
def testAsDict(self): p = create_path() config = ConfigXml(filename=str(p), env_config="DICT") config["omero.data.dir"] = "HOME" config.close() initial = self.initial("DICT") _ = SubElement(initial[0][0], "property", name="omero.data.dir", value="HOME") _ = SubElement(initial, "properties", id="DICT") _ = SubElement(_, "property", name="omero.data.dir", value="HOME") self.assertXml(initial, XML(p.text()))
def test_get_unit_and_value(self): # units defaults to MICROMETER fake = create_path("image", "&physicalSizeX=1.0.fake") pixIds = self.import_image(filename=fake.abspath()) self.args = self.login_args() + [ "obj", "get", "Pixels:%s" % pixIds[0], "physicalSizeX" ] state = self.go() assert state.get_row(0) == "1.0 MICROMETER"
def write_config(data): p = create_path() i = initial() for k, v in data.items(): for x in i[0:2]: # __ACTIVE__ & default SubElement(x, "property", name=k, value=v) string = tostring(i, "utf-8") txt = xml.dom.minidom.parseString(string).toprettyxml(" ", "\n", None) p.write_text(txt) return p
def testCannotCreateLock(self): d = create_path(folder=True) filename = str(d / "config.xml") lock_filename = "%s.lock" % filename with open(lock_filename, "w") as fo: fo.write("dummy\n") os.chmod(lock_filename, 0444) with pytest.raises(IOError) as excinfo: ConfigXml(filename).close() assert excinfo.value.errno == errno.EACCES
def write_config(data): p = create_path() i = initial() for k, v in list(data.items()): for x in i[0:2]: # __ACTIVE__ & default SubElement(x, "property", name=k, value=v) string = tostring(i, 'utf-8') txt = xml.dom.minidom.parseString(string).toprettyxml(" ", "\n", None) p.write_text(txt) return p
def __init__(self, client, user): self.client = client self.user = user self.admin = self.client.sf.getAdminService() self.query = self.client.sf.getQueryService() self.update = self.client.sf.getUpdateService() self.context = self.admin.getEventContext() self.img = create_path("cliimportfixture.", ".png") i = Image.new(mode="1", size=[8, 8]) i.save(self.img)
def testCannotCreateLock(self): d = create_path(folder=True) filename = str(old_div(d, "config.xml")) lock_filename = "%s.lock" % filename with open(lock_filename, "w") as fo: fo.write("dummy\n") os.chmod(lock_filename, 0o444) with pytest.raises(IOError) as excinfo: ConfigXml(filename).close() assert excinfo.value.errno == errno.EACCES
def testSettings510Upgrade(self): """ When upgraded 5.0.x properties to 5.1.0 or later, if omero.web.ui.top_links is set, we need to prepend 'Data', 'History' and 'Help' links """ beforeUpdate = '[["Figure", "figure_index"]]' afterUpdate = '[["Data", "webindex", ' \ '{"title": "Browse Data via Projects, Tags etc"}], ' \ '["History", "history", ' \ '{"title": "History"}], ' \ '["Help", "https://help.openmicroscopy.org/", ' \ '{"target": "new", "title": ' \ '"Open OMERO user guide in a new tab"}], ' \ '["Figure", "figure_index"]]' p = create_path() XML = Element("icegrid") active = SubElement(XML, "properties", id="__ACTIVE__") default = SubElement(XML, "properties", id="default") for properties in (active, default): # Include a property to indicate version is post-4.2.0 SubElement(properties, "property", name="omero.config.version", value="4.2.1") SubElement(properties, "property", name="omero.web.ui.top_links", value=beforeUpdate) string = tostring(XML, 'utf-8') txt = xml.dom.minidom.parseString(string).toprettyxml(" ", "\n", None) p.write_text(txt) def compare_json_maps(config, afterUpdate): m = config.as_map() beforeUpdate = m["omero.web.ui.top_links"] assert json.loads(beforeUpdate) == json.loads(afterUpdate) config = ConfigXml(filename=str(p), env_config="default") try: compare_json_maps(config, afterUpdate) finally: config.close() # After config.close() calls config.save() new version should be 5.1.0 config = ConfigXml(filename=str(p), env_config="default") try: # Check version has been updated assert config.version() == "5.1.0" # And that top_links has not been modified further compare_json_maps(config, afterUpdate) finally: config.close()
def testAsDict(self): p = create_path() config = ConfigXml(filename=str(p), env_config="DICT") config["omero.data.dir"] = "HOME" config.close() i = initial("DICT") _ = SubElement(i[0][0], "property", name="omero.data.dir", value="HOME") _ = SubElement(i, "properties", id="DICT") _ = SubElement(_, "property", name="omero.data.dir", value="HOME") assertXml(i, XML(p.text()))
def testReplace(self): p = create_path(suffix=".py") p.write_text(scriptText) # test replace with user script (not official) # Sets current script self.cli.invoke(self.args + ["upload", str(p)], strict=True) newId = self.cli.get("script.file.id") self.cli.invoke(self.args + ["list", "user"], strict=True) replaceArgs = self.args + ["replace", str(newId), str(p)] self.cli.invoke(replaceArgs, strict=True)
def test_upload_file(self): """Test the upload of the file, the creation is tested above""" f = create_path() f.write_text("""Test test_upload_file %s """ % self.uuid()) update_service = self.client.sf.getUpdateService() of = scriptUtil.create_file(update_service, str(f)) store = self.client.sf.createRawFileStore() try: scriptUtil.upload_file(store, of, f) finally: store.close()
def testLoad(self): tmp = create_path() tmp.write_text("foo") self.cli = CLI() self.cli.register("load", LoadControl, "help") with pytest.raises(NonZeroReturnCode): self.cli.invoke("load %s" % tmp, strict=True) self.cli.invoke("load -k %s" % tmp, strict=True) self.cli.invoke("load --keep-going %s" % tmp, strict=True)
def as_dictionary(path, readers="", extra_args=None): """Run as_stdout, parses the output and returns a dictionary of the form:: { some_file_in_group : [ some_file_in_group some_other_file_in_group ... last_file_in_group ], some_file_in_second_group : ... } you can pass more arguments to the `import` command through the extra_args argument in the form of a list. to_import = as_dictionary("/my/dir/with_tifs", extra_args=["--depth", "6"]) will go through the directories with a depth level of 6 instead of the default 4. Arguments of interest might be: `debugging`, `report`, `logback`. Note that the command runs locally so options such as `--exclude` will not work as they need information from the server. """ t = create_path("candidates", "err") path = _to_list(path) path.insert(0, "---file=%s" % t) try: as_stdout(path, readers=readers, extra_args=extra_args) f = open(str(t), "r") output = f.readlines() f.close() finally: remove_path(t) gline = -1 key = None groups = {} for line in output: line = line.strip() if len(line) == 0: continue if line.startswith("#"): gline = -1 else: if gline == -1: gline = 1 key = line groups[key] = [line] else: groups[key].append(line) return groups
def testLoadInvalidKey(self, capsys, invalidline, invalidkey): self.invoke("set A B") self.assertStdoutStderr(capsys) to_load = create_path() to_load.write_text("C=D\n%s\nH=I\n" % invalidline) with pytest.raises(NonZeroReturnCode): self.invoke("load %s" % to_load) self.assertStdoutStderr(capsys, err="Illegal property name: %s" % invalidkey) self.invoke("get") self.assertStdoutStderr(capsys, out="A=B")
def importMIF(self, seriesCount=0, name=None, client=None, with_companion=False, skip="all", **kwargs): if client is None: client = self.client if name is None: name = "importMIF" try: globalMetadata = kwargs.pop("GlobalMetadata") except: globalMetadata = None if globalMetadata: with_companion = True append = "" # Only include series count if enabled; in the case of plates, # this will be unused if seriesCount >= 1: append = "series=%d%s" % (seriesCount, append) if kwargs: for k, v in kwargs.items(): append += "&%s=%s" % (k, v) query = client.sf.getQueryService() fake = create_path(name, "&%s.fake" % append) if with_companion: ini = open(fake.abspath() + ".ini", "w") if globalMetadata: ini.write("[GlobalMetadata]\n") for k, v in globalMetadata.items(): ini.write("%s=%s\n" % (k, v)) ini.close() pixelIds = self.import_image(filename=fake.abspath(), client=client, skip=skip, **kwargs) if seriesCount >= 1: assert seriesCount == len(pixelIds) images = [] for pixIdStr in pixelIds: pixels = query.get("Pixels", long(pixIdStr)) images.append(pixels.getImage()) return images
def testReadOnlyConfigFailsOnEnv2(self): old = os.environ.get("OMERO_CONFIG") os.environ["OMERO_CONFIG"] = "default" try: p = create_path() p.chmod(0444) # r--r--r-- pytest.raises(Exception, ConfigXml, filename=str(p)) finally: if old is None: del os.environ["OMERO_CONFIG"] else: os.environ["OMERO_CONFIG"] = old
def uploadFileset(self, proc, files): tmp = create_path() hashes = [] for idx, file in enumerate(files): prx = proc.getUploader(idx) self.client.download(file, filename=tmp) hashes.append(self.client.sha1(tmp)) with open(tmp, "r") as source: self.client.write_stream(source, prx) prx.close() tmp.remove() return proc.verifyUpload(hashes)
def _checkstd(self, output, which): rfile = output.val[which] ofile = rfile.val assert ofile tmppath = create_path("clitest") try: self.client.download(ofile, str(tmppath)) assert os.path.getsize(str(tmppath)) return tmppath.text() finally: remove_path(tmppath)
def _checkstd(self, output, which): rfile = output.val[which] ofile = rfile.val assert ofile tmppath = create_path("pingtest") try: self.client.download(ofile, str(tmppath)) assert os.path.getsize(str(tmppath)) return tmppath.text() finally: remove_path(tmppath)
def testReplaceOfficial(self): p = create_path(suffix=".py") p.write_text(scriptText) # test replace with official script self.args = self.root_login_args() + ["script"] uploadArgs = self.args + ["upload", str(p), "--official"] self.cli.invoke(uploadArgs, strict=True) # Sets current script newId = self.cli.get("script.file.id") self.cli.invoke(self.args + ["list"], strict=True) replaceArgs = self.args + ["replace", str(newId), str(p)] self.cli.invoke(replaceArgs, strict=True)
def testOldVersionDetected(self): p = create_path() config = ConfigXml(filename=str(p)) X = config.XML O = SubElement(X, "properties", {"id": "old"}) SubElement(O, "property", {"omero.ldap.keystore": "/Foo"}) config.close() try: config = ConfigXml(filename=str(p)) assert False, "Should throw" except: pass
def testUploadDownload(self): uploaded = tmpfile() downloaded = create_path() ofile = self.client.upload(str(uploaded), type="text/plain") self.client.download(ofile, str(downloaded)) lines = downloaded.lines() self.assert_("abc\n" == lines[0], lines[0]) self.assert_("def\n" == lines[1], lines[1]) self.assert_("123\n" == lines[2], lines[2]) sha1_upload = self.client.sha1(str(uploaded)) sha1_download = self.client.sha1(str(downloaded)) self.assertEquals(sha1_upload, sha1_download, "%s!=%s" % (sha1_upload, sha1_download))
def createCsv(self, colNames="Well,Well Type,Concentration", rowData=("A1,Control,0", "A2,Treatment,10")): csvFileName = create_path("test", ".csv") csvFile = open(csvFileName, 'w') try: csvFile.write(colNames) csvFile.write("\n") csvFile.write("\n".join(rowData)) finally: csvFile.close() return str(csvFileName)