Changeset 0863065 in sasview


Ignore:
Timestamp:
Oct 25, 2018 12:09:11 PM (3 weeks ago)
Author:
Jeff Krzywon <jkrzywon@…>
Branches:
unittest-saveload
Parents:
6af5d75
Message:

Start of simple tests for loading data via the sasview gui, rather than the sascalc data loader.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/projectsaveandload/test/utest_project.py

    r08f921e r0863065  
    44 
    55import os 
    6 import sys 
    76import unittest 
    87import warnings 
    98import threading 
     9from time import sleep 
    1010 
     11import sas.sasview.sasview as sasview 
    1112from sas.sascalc.dataloader.loader import Loader 
    1213from sas.sascalc.fit.pagestate import Reader as fit_state_reader 
     
    1819 
    1920TEMP_FOLDER = "temp_folder" 
     21DATA_1D = "test_data" + os.path.sep + "data1D.h5" 
     22DATA_2D = "test_data" + os.path.sep + "data2D.h5" 
    2023STATE_LOADERS = [fit_state_reader, invariant_reader, pr_reader, corfunc_reader] 
    2124 
     
    2932        self.addCleanup(self.remove_dir) 
    3033        self.loader = Loader() 
    31         self.data1d = self.loader.load("test_data/data1D.h5") 
    32         self.data2d = self.loader.load("test_data/data2D.h5") 
    33         self.sasviewThread = sasviewThread() 
    34         self.sasviewThread.start_local() 
     34        self.data1d = self.loader.load(DATA_1D) 
     35        self.data2d = self.loader.load(DATA_2D) 
     36        self.sasviewThread = sasviewThread(False) 
    3537        if not (os.path.isdir(TEMP_FOLDER)): 
    3638            os.makedirs(TEMP_FOLDER) 
     39        self.sasviewThread.lock.acquire() 
     40        self.sasviewThread.start_local() 
     41        while self.sasviewThread.frame is None: 
     42            sleep(0.05) 
     43        while self.sasviewThread.frame._data_panel is None: 
     44            sleep(0.05) 
     45        # TODO: Do we need the frame to be visible to perform operations? 
     46        while not self.sasviewThread.frame.IsShown(): 
     47            sleep(2) 
     48        # self.sasviewThread.frame.get_data(DATA_1D) 
     49        # self.sasviewThread.frame.get_data(DATA_2D) 
    3750 
    3851    def tearDown(self): 
     52        self.sasviewThread.lock.release() 
     53        self.sasviewThread.frame = None 
    3954        self.remove_dir() 
    40         if hasattr(self.sasviewThread, "isAlive"): 
    41             if self.sasviewThread.isAlive(): 
    42                 print("TODO: Close app directly") 
    43                 self.app.gui.Close() 
    44                 pass 
    4555 
    4656    def remove_dir(self): 
     
    5262        Test saving and loading a project with a single data set sent to fitting 
    5363        """ 
    54         self.sasviewThread.join(5) 
     64        self.assertTrue(self.data1d is not None) 
     65        self.assertTrue(self.data2d is not None) 
    5566        self.assertTrue(1 == 1) 
    5667 
     
    6879    def __init__(self, autoStart=True): 
    6980        threading.Thread.__init__(self) 
     81        self.lock = threading.Lock() 
     82        self.lock.acquire()  # lock until variables are set 
    7083        self.setDaemon(1) 
    7184        self.start_orig = self.start 
    7285        self.start = self.start_local 
    7386        self.frame = None  # to be defined in self.run 
    74         self.lock = threading.Lock() 
    75         self.lock.acquire()  # lock until variables are set 
    7687        if autoStart: 
    7788            self.start()  # automatically start thread on init 
     89        self.lock.release() 
    7890 
    7991    def run(self): 
    80         import sas.sasview.sasview as sasview 
    81         app = sasview.run_gui() 
    82         self.frame = app.frame 
    83  
    84         # define frame and release lock 
    85         # The lock is used to make sure that SetData is defined. 
    86         self.lock.release() 
    87  
    88         app.MainLoop() 
     92        app = sasview.run_gui(True) 
     93        self.frame = app.gui.frame 
     94        app.gui.MainLoop() 
    8995 
    9096    def start_local(self): 
    9197        self.start_orig() 
    92         # After thread has started, wait until the lock is released 
    93         # before returning so that functions get defined. 
    94         self.lock.acquire() 
Note: See TracChangeset for help on using the changeset viewer.