Skip to content
Snippets Groups Projects
SimplePythonAPITest.h 2.9 KiB
Newer Older
#ifndef SIMPLEPYTHONAPITEST_H_
#define SIMPLEPYTHONAPITEST_H_

//--------------------------------
// Includes
//--------------------------------
#include <fstream>
#include <cxxtest/TestSuite.h>

#include "MantidPythonAPI/SimplePythonAPI.h"
#include "MantidAPI/FrameworkManager.h"

class SimplePythonAPITest : public CxxTest::TestSuite
{
public:

  SimplePythonAPITest()
  {
    Mantid::API::FrameworkManager::Instance();
  }

  void testCreateModule()
  {
    using namespace Mantid::PythonAPI;
    //first call the function to create the module file
Gigg, Martyn Anthony's avatar
Gigg, Martyn Anthony committed
    Poco::File apimodule(SimplePythonAPI::getModuleFilename());
    //has it been written ?

    //does it contain what we expect
    TS_ASSERT_EQUALS(line, "from MantidPythonAPI import *");
    TS_ASSERT_EQUALS(line, "from libMantidPythonAPI import *");
    //next line should be MantidFramework import
    getline( is, line );
    TS_ASSERT_EQUALS(line, std::string("from MantidFramework import *"));
    //next line should be os import
    getline( is, line );
    TS_ASSERT_EQUALS(line, std::string("import os"));
    //next line should be string import
    getline( is, line );
    TS_ASSERT_EQUALS(line, std::string("import string"));
    TS_ASSERT_EQUALS(line, "def setWorkingDirectory(path):");
    getline(is, line);
    TS_ASSERT_EQUALS(line, "\tos.chdir(path)");

    //next non-blank line should be help()
    //eat blank lines
    while( getline(is, line) && line.empty() ) 
    {
    }
    
    TS_ASSERT_EQUALS(line, std::string("def numberRows(descr, fw):"))
    while( getline(is, line) && !line.empty() ) 
    {
    }

    getline(is, line);
    TS_ASSERT_EQUALS(line, std::string("def createParamTable(param_list, dialog):"))
    while( getline(is, line) && !line.empty() ) 
    {
    }

    getline(is, line);
    TS_ASSERT_EQUALS(line, "def mtdGlobalHelp():");

    //skip over help
    while( getline(is, line) && !line.empty() ) 
      {
      }
    //it should be an algorithm definition but first is a comment line
    getline(is,line);
    getline(is,line);
    bool found(false);
    if( line.find("def") == 0 ) found = true;
    TS_ASSERT_EQUALS(found, true);

    getline(is, line);
    found = false;
    if( line.find("createAlgorithm") != std::string::npos ) found = true;
    TS_ASSERT_EQUALS(found, true);

    int setprop(0);
    while( getline(is, line) )
      {
	if( line.find("setPropertyValue") != std::string::npos )
	  ++setprop;
      }
    TS_ASSERT( setprop > 0 );

    is.close();
    // remove
    TS_ASSERT_THROWS_NOTHING( apimodule.remove() );
    TS_ASSERT( !apimodule.exists() );