Exemplo n.º 1
0
    def setUp(self):
        unittest.TestCase.setUp(self)

        # Temporary directory
        self.tmpdir = tempfile.mkdtemp()

        compositions = [{29: 0.5, 79: 0.5}, {29: 0.2, 79: 0.8}]
        self.results = Results(compositions, 123.456, 12, 'TestIterator',
                               'TestConvergor')

        relpath = os.path.join('..', '..', 'testdata', 'quant_results.zip')
        self.results_zip = os.path.join(os.path.dirname(__file__), relpath)
Exemplo n.º 2
0
class TestResults(unittest.TestCase):
    def setUp(self):
        unittest.TestCase.setUp(self)

        # Temporary directory
        self.tmpdir = tempfile.mkdtemp()

        compositions = [{29: 0.5, 79: 0.5}, {29: 0.2, 79: 0.8}]
        self.results = Results(compositions, 123.456, 12, 'TestIterator',
                               'TestConvergor')

        relpath = os.path.join('..', '..', 'testdata', 'quant_results.zip')
        self.results_zip = os.path.join(os.path.dirname(__file__), relpath)

    def tearDown(self):
        unittest.TestCase.tearDown(self)

        shutil.rmtree(self.tmpdir, ignore_errors=True)

    def testskeleton(self):
        self.assertTrue(True)

    def testload(self):
        results = Results.load(self.results_zip)

        self.assertEqual(2, results.iterations)
        self.assertEqual(2, len(results.compositions))
        self.assertAlmostEqual(0.5, results.compositions[0][29], 4)
        self.assertAlmostEqual(0.5, results.compositions[0][79], 4)
        self.assertAlmostEqual(0.2, results.compositions[-1][29], 4)
        self.assertAlmostEqual(0.8, results.compositions[-1][79], 4)

        self.assertAlmostEqual(0.0, results.compositions[-1][99],
                               4)  # test defaultdict

        self.assertAlmostEqual(123.456, results.elapsed_time_s, 4)
        self.assertEqual(12, results.max_iterations)
        self.assertEqual('TestIterator', results.iterator)
        self.assertEqual('TestConvergor', results.convergor)

    def testsave(self):
        zipfilepath = os.path.join(self.tmpdir, 'results.zip')
        self.results.save(zipfilepath)

        with open(zipfilepath, 'r') as fp:
            zipfile = ZipFile(fp, 'r')

            namelist = zipfile.namelist()
            self.assertTrue('compositions.csv' in namelist)
            self.assertTrue('stats.cfg' in namelist)

            zipfile.close()
Exemplo n.º 3
0
class TestResults(unittest.TestCase):

    def setUp(self):
        unittest.TestCase.setUp(self)

        # Temporary directory
        self.tmpdir = tempfile.mkdtemp()

        compositions = [{29:0.5, 79:0.5}, {29:0.2, 79:0.8}]
        self.results = Results(compositions, 123.456, 12, 'TestIterator', 'TestConvergor')

        relpath = os.path.join('..', '..', 'testdata', 'quant_results.zip')
        self.results_zip = os.path.join(os.path.dirname(__file__), relpath)

    def tearDown(self):
        unittest.TestCase.tearDown(self)

        shutil.rmtree(self.tmpdir, ignore_errors=True)

    def testskeleton(self):
        self.assertTrue(True)

    def testload(self):
        results = Results.load(self.results_zip)

        self.assertEqual(2, results.iterations)
        self.assertEqual(2, len(results.compositions))
        self.assertAlmostEqual(0.5, results.compositions[0][29], 4)
        self.assertAlmostEqual(0.5, results.compositions[0][79], 4)
        self.assertAlmostEqual(0.2, results.compositions[-1][29], 4)
        self.assertAlmostEqual(0.8, results.compositions[-1][79], 4)

        self.assertAlmostEqual(0.0, results.compositions[-1][99], 4)  # test defaultdict

        self.assertAlmostEqual(123.456, results.elapsed_time_s, 4)
        self.assertEqual(12, results.max_iterations)
        self.assertEqual('TestIterator', results.iterator)
        self.assertEqual('TestConvergor', results.convergor)

    def testsave(self):
        zipfilepath = os.path.join(self.tmpdir, 'results.zip')
        self.results.save(zipfilepath)

        with open(zipfilepath, 'r') as fp:
            zipfile = ZipFile(fp, 'r')

            namelist = zipfile.namelist()
            self.assertTrue('compositions.csv' in namelist)
            self.assertTrue('stats.cfg' in namelist)

            zipfile.close()
Exemplo n.º 4
0
    def _save_results(self, measurement, iterator, convergor,
                      elapsed_time_s, zipfilepath):
        """
        Generates the results from the measurement outputs after the measurement 
        was run and then save them at the specified location.
        """
        # Compositions
        rules = measurement.get_rules()

        compositions = []
        for composition in map(dict, iterator): # copy
            self._apply_composition_rules(rules, composition)
            compositions.append(composition)

        # Create results
        results = QuantResults(compositions, elapsed_time_s,
                               self._max_iterations, iterator, convergor)
        results.save(zipfilepath)
Exemplo n.º 5
0
    def setUp(self):
        unittest.TestCase.setUp(self)

        # Temporary directory
        self.tmpdir = tempfile.mkdtemp()

        compositions = [{29:0.5, 79:0.5}, {29:0.2, 79:0.8}]
        self.results = Results(compositions, 123.456, 12, 'TestIterator', 'TestConvergor')

        relpath = os.path.join('..', '..', 'testdata', 'quant_results.zip')
        self.results_zip = os.path.join(os.path.dirname(__file__), relpath)
Exemplo n.º 6
0
    def testrun(self):
        self.runner.start()
        self.runner.put(self.m)
        self.runner.join()

        filepath = os.path.join(self.outputdir, 'PAP.zip')
        results = Results.load(filepath)

        composition = results.compositions[-1]
        self.assertAlmostEqual(0.21069, composition[29], 4)
        self.assertAlmostEqual(0.78931, composition[79], 4)

        self.assertEqual(results.iterations, len(results.compositions))
Exemplo n.º 7
0
    def testrun(self):
        self.runner.start()
        self.runner.put(self.m)
        self.runner.join()

        filepath = os.path.join(self.outputdir, 'PAP.zip')
        results = Results.load(filepath)

        composition = results.compositions[-1]
        self.assertAlmostEqual(0.21069, composition[29], 4)
        self.assertAlmostEqual(0.78931, composition[79], 4)

        self.assertEqual(results.iterations, len(results.compositions))
Exemplo n.º 8
0
    def testload(self):
        results = Results.load(self.results_zip)

        self.assertEqual(2, results.iterations)
        self.assertEqual(2, len(results.compositions))
        self.assertAlmostEqual(0.5, results.compositions[0][29], 4)
        self.assertAlmostEqual(0.5, results.compositions[0][79], 4)
        self.assertAlmostEqual(0.2, results.compositions[-1][29], 4)
        self.assertAlmostEqual(0.8, results.compositions[-1][79], 4)

        self.assertAlmostEqual(0.0, results.compositions[-1][99], 4)  # test defaultdict

        self.assertAlmostEqual(123.456, results.elapsed_time_s, 4)
        self.assertEqual(12, results.max_iterations)
        self.assertEqual('TestIterator', results.iterator)
        self.assertEqual('TestConvergor', results.convergor)
Exemplo n.º 9
0
    def testload(self):
        results = Results.load(self.results_zip)

        self.assertEqual(2, results.iterations)
        self.assertEqual(2, len(results.compositions))
        self.assertAlmostEqual(0.5, results.compositions[0][29], 4)
        self.assertAlmostEqual(0.5, results.compositions[0][79], 4)
        self.assertAlmostEqual(0.2, results.compositions[-1][29], 4)
        self.assertAlmostEqual(0.8, results.compositions[-1][79], 4)

        self.assertAlmostEqual(0.0, results.compositions[-1][99],
                               4)  # test defaultdict

        self.assertAlmostEqual(123.456, results.elapsed_time_s, 4)
        self.assertEqual(12, results.max_iterations)
        self.assertEqual('TestIterator', results.iterator)
        self.assertEqual('TestConvergor', results.convergor)
Exemplo n.º 10
0
 def _validate(self, filepath):
     Results.load(filepath)
Exemplo n.º 11
0
 def _validate(self, filepath):
     Results.load(filepath)