Exemple #1
0
    def test_add_python_package(self):
        """Test add_python_package."""

        # 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='tensorflow', min_version='0.12.0'),
            override=True)
        dependency_helper.add_python_package(
            dependency=VersionedDependency(
                name='kubernetes', min_version='0.8.0'),
            override=False)
        dependency_helper.add_python_package(
            dependency=VersionedDependency(name='pytorch', version='0.3.0'))
        dependency_helper.generate_pip_requirements(temp_file)
        golden_requirement_payload = '''\
tensorflow >= 0.12.0
kubernetes >= 0.6.0
pytorch >= 0.3.0, <= 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)
Exemple #2
0
 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())
Exemple #3
0
 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')
Exemple #4
0
    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)
Exemple #5
0
 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())