def test_config_non_existing_service(self):
        compute = singularity.Compute()
        service = TestSingularityMap.Service()

        volume_map = compute.configuration_map(service)
        # Should be empty
        self.assertEqual(volume_map, [])
    def test_config_test_service_nt(self):
        compute = singularity.Compute()
        service = TestSingularityMap.Service()

        service.compose_service_name = "test"
        volume_map = compute.configuration_map(service)
        ans = [('/tmp', '/bar'), ('/tmp/.X11-unix', '/tmp/.X11-unix')]
        self.assertEqual(volume_map, ans)
 def setUp(self):
     # This will reset the _connection to an uninitialized state
     self.patches.append(
         mock.patch.object(
             terra.compute.utils.ComputeHandler, '_connection',
             mock.PropertyMock(return_value=singularity.Compute())))
     # Configure for singularity
     self.config.compute = {'arch': 'singularity'}
     super().setUp()
    def test_config_terra_service(self):
        compute = singularity.Compute()
        service = TestSingularityMap.Service()

        service.compose_service_name = "bar"
        volume_map = compute.configuration_map(service)
        ans = [
            ('/tmp', '/bar'),
            ('/opt/projects/terra/terra_dsm/external/terra', '/src'),
            ('/opt/projects/terra/terra_dsm/external/terra', '/terra'),
            ('/tmp/.X11-unix', '/tmp/.X11-unix'),
            ('/opt/projects/terra/terra_dsm/external/terra/external/vsi_common',
             '/vsi')
        ]
        self.assertEqual(volume_map, ans)
    def test_run(self):
        compute = singularity.Compute()

        self.return_value = 0
        # This part of the test looks fragile
        compute.run(MockJustService())
        # Run a singularity service
        self.assertEqual(
            ('singular-compose', '-f', 'file1', 'run', 'launch', 'ls'),
            self.just_args)
        self.assertEqual({'env': {'BAR': 'FOO'}}, self.just_kwargs)

        # Test a non-zero return value
        self.return_value = 1
        with self.assertRaises(base.ServiceRunFailed):
            compute.run(MockJustService())
    def test_config(self):
        compute = singularity.Compute()

        self.assertEqual(compute.config(MockJustService()), {
            'environment': {
                'foo': 'bar'
            },
            'stuff': ['boo', 'far']
        })
        self.assertEqual(
            ('singular-compose', '-f', 'file1', 'config-null', 'launch'),
            self.just_args)

        self.assertEqual(
            {
                'stdout': singularity.PIPE,
                'env': {
                    'BAR': 'FOO'
                },
                'justfile': None
            }, self.just_kwargs)