def test_generate_requirement(self): """ Test generating requirement file """ # prepare test_data_dir = os.path.join(os.path.dirname(__file__), 'testdata') temp_file = os.path.join(test_data_dir, 'test_requirements.tmp') dependency_helper = DependencyHelper() dependency_helper.add_python_package(dependency=VersionedDependency( name='tensorflow', min_version='0.10.0', max_version='0.11.0')) dependency_helper.add_python_package(dependency=VersionedDependency( name='kubernetes', min_version='0.6.0')) dependency_helper.add_python_package(dependency=VersionedDependency( name='pytorch', max_version='0.3.0')) dependency_helper.generate_pip_requirements(temp_file) golden_requirement_payload = '''\ tensorflow >= 0.10.0, <= 0.11.0 kubernetes >= 0.6.0 pytorch <= 0.3.0 ''' with open(temp_file, 'r') as f: target_requirement_payload = f.read() self.assertEqual(target_requirement_payload, golden_requirement_payload) os.remove(temp_file)
def test_prepare_docker_with_py_and_dependency(self): """ Test the whole prepare docker from python function and dependencies """ # prepare test_data_dir = os.path.join(os.path.dirname(__file__), 'testdata') python_filepath = os.path.join(test_data_dir, 'basic.py') local_tarball_path = os.path.join(test_data_dir, 'test_docker.tar.gz') # check docker_helper = DockerfileHelper(arc_dockerfile_name='dockerfile') dependencies = { VersionedDependency(name='tensorflow', min_version='0.10.0', max_version='0.11.0'), VersionedDependency(name='kubernetes', min_version='0.6.0'), } docker_helper.prepare_docker_tarball_with_py( arc_python_filename='main.py', python_filepath=python_filepath, base_image='gcr.io/ngao-mlpipeline-testing/tensorflow:1.8.0', local_tarball_path=local_tarball_path, dependency=dependencies) temp_tarball_handle = tarfile.open(local_tarball_path) temp_files = temp_tarball_handle.getmembers() self.assertTrue(len(temp_files) == 3) for temp_file in temp_files: self.assertTrue(temp_file.name in ['dockerfile', 'main.py', 'requirements.txt']) # clean up os.remove(local_tarball_path)
def test_minmax_version(self): """ test if min_version and max_version are configured when version is not given """ version = VersionedDependency(name='tensorflow', min_version='0.1.0', max_version='0.4.0') self.assertTrue(version.min_version == '0.1.0') self.assertTrue(version.max_version == '0.4.0') self.assertTrue(version.has_versions())
def test_version(self): """ test version overrides min_version and max_version """ version = VersionedDependency(name='tensorflow', version='0.3.0', min_version='0.1.0', max_version='0.4.0') self.assertTrue(version.min_version == '0.3.0') self.assertTrue(version.max_version == '0.3.0') self.assertTrue(version.has_versions()) self.assertTrue(version.name == 'tensorflow')
def test_generate_requirement(self): # prepare test_data_dir = os.path.join(os.path.dirname(__file__), 'testdata') temp_file = os.path.join(test_data_dir, 'test_requirements.tmp') dependencies = [ VersionedDependency(name='tensorflow', min_version='0.10.0', max_version='0.11.0'), VersionedDependency(name='kubernetes', min_version='0.6.0'), ] _dependency_to_requirements(dependencies, filename=temp_file) golden_payload = '''\ tensorflow >= 0.10.0, <= 0.11.0 kubernetes >= 0.6.0 ''' with open(temp_file, 'r') as f: target_payload = f.read() self.assertEqual(target_payload, golden_payload) os.remove(temp_file)
def test_no_version(self): """ test the no version scenario """ version = VersionedDependency(name='tensorflow') self.assertFalse(version.has_min_version()) self.assertFalse(version.has_max_version()) self.assertFalse(version.has_versions())