def test_package(self): with mkvenv() as tempdir: with chdir(tempdir): subprocess.check_call(["sh", filepath("create.sh")]) subprocess.check_call(["sh", filepath("cd.sh")]) cd_path = pathlib.Path(filepath("cd.sh")) pkg = cd_path.read_text().strip().split()[-1] with chdir(pkg): # Check that the imports header is correct check_imports_path = pathlib.Path( filepath("test_model_imports.txt") ) check_imports = check_imports_path.read_text().strip() real_imports_path = pathlib.Path("tests", "test_model.py") real_imports = real_imports_path.read_text().strip() self.assertTrue(real_imports.startswith(check_imports)) # Run the pip install subprocess.check_call(["sh", filepath("pip_install.sh")]) # Run the tests subprocess.check_call(["sh", filepath("unittest.sh")]) subprocess.check_call( ["sh", filepath("unittest_logging.sh")] ) # Try training subprocess.check_call( [ "sh", str( pathlib.Path(__file__).parent.parent / "slr" / "train_data.sh" ), ] ) subprocess.check_call(["sh", filepath("train.sh")])
def directory_with_csv_files(): with tempfile.TemporaryDirectory() as tempdir: with chdir(tempdir): subprocess.check_output(["sh", sh_filepath("train_data.sh")]) subprocess.check_output(["sh", sh_filepath("test_data.sh")]) subprocess.check_output(["sh", sh_filepath("predict_data.sh")]) yield tempdir
def directory_with_data_files(): with tempfile.TemporaryDirectory() as tempdir: with chdir(tempdir): # Replace Yann's website with GitHub mirror for stability image_data_sh_path = pathlib.Path(sh_filepath("image_data.sh")) image_data_sh_contents = image_data_sh_path.read_text().split("\n") # First line is the curl command curl = image_data_sh_contents[0].split()[:-1] # Make 4 curl commands and then append the sha validation image_data_sh_github_mirror_path = pathlib.Path( tempdir, "image_data.sh") image_data_sh_github_mirror_path.write_text("\n".join([ " ".join(curl + [url]) for url in [ "https://github.com/intel/dffml/files/4283897/train-labels-idx1-ubyte.gz", "https://github.com/intel/dffml/files/4283898/train-images-idx3-ubyte.gz", "https://github.com/intel/dffml/files/6138929/t10k-labels-idx1-ubyte.gz", "https://github.com/intel/dffml/files/6138930/t10k-images-idx3-ubyte.gz", ] ] + image_data_sh_contents[1:], )) subprocess.check_output( ["bash", str(image_data_sh_github_mirror_path)]) subprocess.check_output(["bash", sh_filepath("image_file.sh")]) for image in pathlib.Path(__file__).parent.glob("*.png"): shutil.copy(str(image.absolute()), image.name) yield tempdir
def directory_with_data_files(): with tempfile.TemporaryDirectory() as tempdir: with chdir(tempdir): subprocess.check_output(["bash", sh_filepath("image_data.sh")]) subprocess.check_output(["bash", sh_filepath("image_file.sh")]) for image in pathlib.Path(__file__).parent.glob("*.png"): shutil.copy(str(image.absolute()), image.name) yield tempdir
async def make_dataflow(ops, operations, seed): # Create temp dir and write op to ops.py with tempfile.TemporaryDirectory() as tmpdirname: # Change directory into the tempdir with chdir(tmpdirname): # Write out op to op.py pathlib.Path(tmpdirname, "ops.py").write_text(ops) # Reload conents sys.path.insert(0, tmpdirname) module = importlib.import_module("ops") importlib.reload(module) sys.path.pop(0) # $ dffml dataflow create $operations -seed $seed with io.StringIO() as dataflow: with contextlib.redirect_stdout(dataflow): await CLI.cli("dataflow", "create", *operations, "-seed", *seed) yield DataFlow._fromdict(**json.loads(dataflow.getvalue()))
async def test_create_from_path(self): # Create temp dir and write op to ops.py with tempfile.TemporaryDirectory() as tmpdirname: # Change directory into the tempdir with chdir(tmpdirname): # Write out op to op.py operation_file_path = pathlib.Path(tmpdirname, "ops.py") operation_file_path.write_text(OP_DEF_STRING) # We make the name the path relative to our cwd operation_qualname = "ops:echo_string" dataflow_file_path = pathlib.Path(tmpdirname, "dataflow.json") # $ dffml dataflow create \ # ops:echo_string get_single with io.StringIO() as dataflow: with contextlib.redirect_stdout(dataflow): await CLI.cli( "dataflow", "create", *[operation_qualname, "get_single"], "-seed", '["OutputString"]=get_single_spec', ) test_dataflow = DataFlow._fromdict( **json.loads(dataflow.getvalue())) # Make sure the operation is in the dataflow self.assertIn(operation_qualname, test_dataflow.operations) # Run the dataflow async for ctx_str, results in run( test_dataflow, [ Input( value="Irregular at magic school", definition=test_dataflow.operations[ operation_qualname].inputs["input_string"], ) ], ): self.assertIn("OutputString", results) self.assertEqual( results["OutputString"], "Irregular at magic school", )
def directory_with_csv_files(): with tempfile.TemporaryDirectory() as tempdir: with chdir(tempdir): subprocess.check_output(["bash", sh_filepath("dataset.sh")]) yield tempdir