michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: import os michael@0: import posixpath michael@0: from StringIO import StringIO michael@0: michael@0: from dmunit import DeviceManagerTestCase michael@0: michael@0: class ExecEnvTestCase(DeviceManagerTestCase): michael@0: michael@0: def runTest(self): michael@0: """Exec test with env vars.""" michael@0: # Push the file michael@0: localfile = os.path.join('test-files', 'test_script.sh') michael@0: remotefile = posixpath.join(self.dm.getDeviceRoot(), 'test_script.sh') michael@0: self.dm.pushFile(localfile, remotefile) michael@0: michael@0: # Run the cmd michael@0: out = StringIO() michael@0: self.dm.shell(['sh', remotefile], out, env={'THE_ANSWER': 42}) michael@0: michael@0: # Rewind the output file michael@0: out.seek(0) michael@0: # Make sure first line is 42 michael@0: line = out.readline() michael@0: self.assertTrue(int(line) == 42) michael@0: michael@0: # Clean up michael@0: self.dm.removeFile(remotefile)