Beispiel #1
0
class TestFeatures(AsyncTestCase):
    def setUp(self):
        self.one = Feature("one", int, 1)
        self.two = Feature("two", float, 2)
        self.three = Feature("three", int, 1)
        self.features = Features(self.one, self.two, self.three)

    async def test_names(self):
        names = self.features.names()
        for check in ["one", "two", "three"]:
            self.assertIn(check, names)
Beispiel #2
0
class TestFeatures(AsyncTestCase):
    def setUp(self):
        self.one = OneFeatureTester()
        self.two = TwoFeatureTester()
        self.three = ThreeFeatureTester()
        self.features = Features(self.one, self.two, self.three)

    async def test_names(self):
        names = self.features.names()
        for check in ["one", "two", "three"]:
            self.assertIn(check, names)
Beispiel #3
0
 def model_dir_path(self, features: Features):
     '''
     Creates the path to the model dir by using the provided model dir and
     the sha256 hash of the concatenated feature names.
     '''
     if self.model_dir is None:
         return None
     model = hashlib.sha256(''.join(features.names()).encode('utf-8'))\
             .hexdigest()
     if not os.path.isdir(self.model_dir):
         raise NotADirectoryError('%s is not a directory' % (self.model_dir))
     return os.path.join(self.model_dir, model)
Beispiel #4
0
class TestFeatures(AsyncTestCase):
    def setUp(self):
        self.one = OneFeatureTester()
        self.two = TwoFeatureTester()
        self.three = ThreeFeatureTester()
        self.features = Features(self.one, self.two, self.three)

    async def test_names(self):
        async with self.features:
            names = self.features.names()
            for check in ["one", "two", "three"]:
                self.assertIn(check, names)

    async def test_applicable(self):
        async with self.features:
            applicable = await self.features.applicable("test")
            self.assertIn(self.one, applicable)
            self.assertIn(self.two, applicable)
            self.assertNotIn(self.three, applicable)

    async def test_evaluate(self):
        async with self.features:
            results = await self.features.evaluate("test")
            self.assertIn(self.one.NAME, results)
            self.assertIn(self.two.NAME, results)
            self.assertNotIn(self.three.NAME, results)
            self.assertEqual(results[self.one.NAME], False)
            self.assertEqual(results[self.two.NAME], True)

    async def test_one_applicable_other_not(self):
        twob = TwoBFeatureTester()
        features = Features(self.two, twob)
        async with features:
            results = await features.evaluate("test")
            self.assertIn(self.two.NAME, results)
            self.assertEqual(len(results), 1)
            self.assertEqual(results[self.two.NAME], True)

    async def test_monitor_progess(self):
        progress = ProgessFeatureTester()
        features = Features(progress)
        async with features:
            data = await features.submit("test")
            logs = await data.logs()
            results = await data.result()
            self.assertTrue(logs)
            self.assertIn("Hi", logs)
            self.assertIn(progress.NAME, results)
            self.assertEqual(len(results), 1)
            self.assertEqual(results[progress.NAME], True)
Beispiel #5
0
 def model_dir_path(self, features: Features):
     """
     Creates the path to the model dir by using the provided model dir and
     the sha384 hash of the concatenated feature names.
     """
     if self.parent.config.directory is None:
         return None
     model = hashlib.sha384(
         "".join(features.names()).encode("utf-8")
     ).hexdigest()
     if not os.path.isdir(self.parent.config.directory):
         raise NotADirectoryError(
             "%s is not a directory" % (self.parent.config.directory)
         )
     return os.path.join(self.parent.config.directory, model)
Beispiel #6
0
class TestFeatures(AsyncTestCase):
    def setUp(self):
        self.one = OneFeatureTester()
        self.two = TwoFeatureTester()
        self.three = ThreeFeatureTester()
        self.features = Features(self.one, self.two, self.three)

    async def test_names(self):
        async with self.features:
            names = self.features.names()
            for check in ["one", "two", "three"]:
                self.assertIn(check, names)

    async def test_applicable(self):
        async with self.features:
            applicable = await self.features.applicable("test")
            self.assertIn(self.one, applicable)
            self.assertIn(self.two, applicable)
            self.assertNotIn(self.three, applicable)

    async def test_evaluate(self):
        async with self.features:
            results = await self.features.evaluate("test")
            self.assertIn(self.one.NAME, results)
            self.assertIn(self.two.NAME, results)
            self.assertNotIn(self.three.NAME, results)
            self.assertEqual(results[self.one.NAME], False)
            self.assertEqual(results[self.two.NAME], True)

    async def test_one_applicable_other_not(self):
        twob = TwoBFeatureTester()
        features = Features(self.two, twob)
        async with features:
            results = await features.evaluate("test")
            self.assertIn(self.two.NAME, results)
            self.assertEqual(len(results), 1)
            self.assertEqual(results[self.two.NAME], True)
Beispiel #7
0
class TestFeatures(AsyncTestCase):
    def setUp(self):
        self.one = OneFeatureTester()
        self.two = TwoFeatureTester()
        self.three = ThreeFeatureTester()
        self.features = Features(self.one, self.two, self.three)

    async def test_names(self):
        async with self.features:
            names = self.features.names()
            for check in ['one', 'two', 'three']:
                self.assertIn(check, names)

    async def test_applicable(self):
        async with self.features:
            applicable = await self.features.applicable('test')
            self.assertIn(self.one, applicable)
            self.assertIn(self.two, applicable)
            self.assertNotIn(self.three, applicable)

    async def test_evaluate(self):
        async with self.features:
            results = await self.features.evaluate('test')
            self.assertIn(self.one.NAME, results)
            self.assertIn(self.two.NAME, results)
            self.assertNotIn(self.three.NAME, results)
            self.assertEqual(results[self.one.NAME], False)
            self.assertEqual(results[self.two.NAME], True)

    async def test_one_applicable_other_not(self):
        twob = TwoBFeatureTester()
        features = Features(self.two, twob)
        async with features:
            results = await features.evaluate('test')
            self.assertIn(self.two.NAME, results)
            self.assertEqual(len(results), 1)
            self.assertEqual(results[self.two.NAME], True)

    async def test_monitor_progess(self):
        progress = ProgessFeatureTester()
        features = Features(progress)
        async with features:
            data = await features.submit('test')
            logs = await data.logs()
            results = await data.result()
            self.assertTrue(logs)
            self.assertIn('Hi', logs)
            self.assertIn(progress.NAME, results)
            self.assertEqual(len(results), 1)
            self.assertEqual(results[progress.NAME], True)

    def test_load_def(self):
        feature = Features.load_def('test', 'float', 10)
        self.assertEqual(feature.NAME, 'test')
        self.assertEqual(feature.dtype(), float)
        self.assertEqual(feature.length(), 10)

    def test_load_defs(self):
        no_def, (one, two) = Features.load_defs('na', 'def:one:float:10',
                                                'def:two:bool:1')
        self.assertEqual(no_def, ['na'])
        self.assertEqual(one.NAME, 'one')
        self.assertEqual(one.dtype(), float)
        self.assertEqual(one.length(), 10)
        self.assertEqual(two.NAME, 'two')
        self.assertEqual(two.dtype(), bool)
        self.assertEqual(two.length(), 1)

    def test_convert_dtype(self):
        self.assertEqual(Features.convert_dtype('float'), float)

    def test_convert_dtype_invalid(self):
        with self.assertRaisesRegex(TypeError, 'Failed to convert'):
            Features.convert_dtype('not a python data type')
Beispiel #8
0
 async def applicable_features(self, features: Features):
     usable = await self.features(features)
     return [name for name in features.names() if name in usable]