Example #1
0
    def test_2(self):
        try:
            subprocess.Popen('ipcluster start --cluster-id=testclusterid --n=1 --daemonize', shell=True)
            time.sleep(5)
            
            args = self.Args()
            args.output_dir = tempfile.mkdtemp()
            args.cluster_id = 'testclusterid'

            logger = AssignParallel.setup_logger()
            AssignParallel.main(args, self.metric, logger)

            assignments = Serializer.load_data(os.path.join(args.output_dir, 'Assignments.h5'))
            r_assignments = Serializer.load_data(os.path.join(fixtures_dir(), 'Assignments.h5'))
            distances = Serializer.load_data(os.path.join(args.output_dir, 'Assignments.h5.distances'))
            r_distances = Serializer.load_data(os.path.join(fixtures_dir(), 'Assignments.h5.distances')) 

            npt.assert_array_equal(assignments, r_assignments)
            npt.assert_array_almost_equal(distances, r_distances)
        
        except:
            raise
        finally:
            shutil.rmtree(args.output_dir)
            subprocess.Popen('ipcluster stop', shell=True).wait()
Example #2
0
    def test_2(self):
        try:
            subprocess.Popen(
                'ipcluster start --cluster-id=testclusterid --n=1 --daemonize',
                shell=True)
            time.sleep(5)

            args = self.Args()
            args.output_dir = tempfile.mkdtemp()
            args.cluster_id = 'testclusterid'

            logger = AssignParallel.setup_logger()
            AssignParallel.main(args, self.metric, logger)

            assignments = io.loadh(
                os.path.join(args.output_dir, 'Assignments.h5'), 'arr_0')
            r_assignments = io.loadh(
                os.path.join(fixtures_dir(), 'Assignments.h5'), 'Data')
            distances = io.loadh(
                os.path.join(args.output_dir, 'Assignments.h5.distances'),
                'arr_0')
            r_distances = io.loadh(
                os.path.join(fixtures_dir(), 'Assignments.h5.distances'),
                'Data')

            npt.assert_array_equal(assignments, r_assignments)
            npt.assert_array_almost_equal(distances, r_distances)

        except:
            raise
        finally:
            shutil.rmtree(args.output_dir)
            subprocess.Popen('ipcluster stop --cluster-id=testclusterid',
                             shell=True).wait()
Example #3
0
def test_setup_logger():
    progname = 'TEST PROGNAME'
    message = 'TEST MESSAGE'
    sys.argv[0] = progname

    fid, path = tempfile.mkstemp()
    stream = open(path, 'w')

    logger = AssignParallel.setup_logger(console_stream=stream)
    logger.info(message)
    
    stream.flush()
    line = open(path).readlines()[0]
    os.unlink(path)

    ok_(line.startswith(progname))
    ok_(line.endswith(message + '\n'))
Example #4
0
def test_setup_logger():
    progname = 'TEST PROGNAME'
    message = 'TEST MESSAGE'
    sys.argv[0] = progname

    fid, path = tempfile.mkstemp()
    stream = open(path, 'w')

    logger = AssignParallel.setup_logger(console_stream=stream)
    logger.info(message)

    stream.flush()
    line = open(path).readlines()[0]
    os.unlink(path)

    ok_(line.startswith(progname))
    ok_(line.endswith(message + '\n'))