def test_port_write_bad_port2(self): good_path = os.path.dirname(os.path.realpath(__file__)) port = OutputPort(port_type='string', value=good_path) try: port.write('test.txt', 'Hello World') except ValueError as e: self.assertIn('Only Directory ports', e.message)
def test_port_write_good_path_abs(self): """ Test write to a port, with an absolute filename """ good_path = os.path.dirname(os.path.realpath(__file__)) file_name = os.path.join(good_path, 'test.txt') port = OutputPort(value=good_path) # Write to abs path try: port.write(file_name, 'Hello World') except ValueError as e: self.assertIn('File name must be relative', e.message)
def test_port_write_good_path(self): """ Test write to a port, relative to the port """ good_path = os.path.dirname(os.path.realpath(__file__)) port = OutputPort(value=good_path) # Write to file relative to port path. port.write('test.txt', 'Hello World') file_name = os.path.join(good_path, 'test.txt') with open(file_name, 'r') as f: self.assertEqual('Hello World', f.read())