Esempio n. 1
0
    def test_to_dict(self, mocked_sys, mocked_datetime):
        creation_time = datetime(2017,
                                 1,
                                 1,
                                 0,
                                 2,
                                 2,
                                 tzinfo=timezone(timedelta(0)))
        mocked_datetime.utcnow.return_value = creation_time
        mocked_sys.version = '3.6.1 (default, Apr  4 2017, 09:40:21) \n' \
                             '[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)]'

        manifest = PackManifest(dependencies=self.dependencies,
                                slots=self.slots)

        # Change updated_at timestamp
        updated_time = datetime(2018,
                                1,
                                1,
                                0,
                                2,
                                2,
                                tzinfo=timezone(timedelta(0)))
        mocked_datetime.utcnow.return_value = updated_time
        manifest.touch_updated_at()

        self.maxDiff = None
        self.assertDictEqual(manifest.to_dict(), self.manifest_dict)
Esempio n. 2
0
    def test_from_dict_wrong_dependencies_arguments(self):

        with self.assertRaises(MLIOPackWrongFormat):
            PackManifest.from_dict({
                'version': 2,
                'dependencies': {
                    'test': {
                        'type': 'module-version'
                    }
                }
            })
Esempio n. 3
0
    def test_from_dict_wrong_dependencies_type(self):

        with self.assertRaises(MLIOPackWrongFormat):
            PackManifest.from_dict({
                'version': 2,
                'dependencies': {
                    'test': {
                        'type': 'unknown'
                    }
                }
            })
Esempio n. 4
0
    def test_from_dict_wrong_dependencies_id(self):

        with self.assertRaises(MLIOPackWrongFormat):
            PackManifest.from_dict({
                'version': 2,
                'dependencies': {
                    'test': {
                        'type': 'module-version',
                        'module_name': 'tests',
                        'version_specs': '==1.1.0'
                    }
                }
            })
Esempio n. 5
0
    def test_touch_update_at(self, mocked_datetime):
        creation_time = datetime(2017, 1, 1, 2, 2, 2)

        mocked_datetime.utcnow.return_value = creation_time
        manifest = PackManifest()

        self.assertEqual(manifest.created_at, creation_time)
        self.assertEqual(manifest.updated_at, creation_time)

        updated_time = datetime(2018, 1, 1, 2, 2, 2)
        mocked_datetime.utcnow.return_value = updated_time
        manifest.touch_updated_at()

        self.assertEqual(manifest.created_at, creation_time)
        self.assertEqual(manifest.updated_at, updated_time)
Esempio n. 6
0
    def test_ctor(self, mocked_datetime):
        creation_time = datetime(2017, 1, 1, 2, 2, 2)
        mocked_datetime.utcnow.return_value = creation_time

        manifest = PackManifest(dependencies=self.dependencies,
                                slots=self.slots)

        self.assertListEqual(sorted(manifest.slots.keys()), ['slot1', 'slot2'])
        self.assertEqual(manifest.slots['slot1'].slot_key, 'slot1')
        self.assertListEqual(
            sorted(manifest.slots['slot1'].dependencies.keys()), [
                'module-version:anothermodule-<=2.2.0,>=1.1.0',
                'module-version:themodule-==1.1.0'
            ])

        self.assertEqual(manifest.slots['slot2'].slot_key, 'slot2')
        self.assertListEqual(
            sorted(manifest.slots['slot2'].dependencies.keys()),
            ['module-version:anothermodule-<=2.2.0,>=1.1.0'])

        self.assertListEqual(sorted(manifest.dependencies.keys()), [
            'module-version:anothermodule-<=2.2.0,>=1.1.0',
            'module-version:themodule-==1.1.0'
        ])
        self.assertEqual(
            manifest.dependencies['module-version:themodule-==1.1.0'].
            dependency_id(), 'module-version:themodule-==1.1.0')
        self.assertEqual(manifest.created_at, creation_time)
        self.assertEqual(manifest.updated_at, creation_time)
Esempio n. 7
0
    def test_ctor_empty(self, mocked_datetime):
        creation_time = datetime(2017, 1, 1, 2, 2, 2)
        mocked_datetime.utcnow.return_value = creation_time

        manifest = PackManifest()

        self.assertDictEqual(manifest.slots, {})
        self.assertDictEqual(manifest.dependencies, {})
        self.assertEqual(manifest.created_at, creation_time)
        self.assertEqual(manifest.updated_at, creation_time)
Esempio n. 8
0
    def test_insert_slot_invalid(self):
        manifest = PackManifest()

        # Insert one slot
        manifest.insert_slot(self.slots_by_id['slot2'])

        # Insert the same slot twice
        with self.assertRaises(SlotKeyError):
            manifest.insert_slot(self.slots_by_id['slot2'])

        # Assure dependencies left intact
        self.assertListEqual(sorted(manifest.dependencies.keys()),
                             ['module-version:anothermodule-<=2.2.0,>=1.1.0'])
Esempio n. 9
0
    def test_from_dict(self):
        creation_time = datetime(2017,
                                 1,
                                 1,
                                 0,
                                 2,
                                 2,
                                 tzinfo=timezone(timedelta(0)))
        updated_time = datetime(2018,
                                1,
                                1,
                                0,
                                2,
                                2,
                                tzinfo=timezone(timedelta(0)))

        manifest = PackManifest.from_dict(self.manifest_dict)

        self.assertListEqual(sorted(manifest.slots.keys()), ['slot1', 'slot2'])
        self.assertEqual(manifest.slots['slot1'].slot_key, 'slot1')
        self.assertListEqual(
            sorted(manifest.slots['slot1'].dependencies.keys()), [
                'module-version:anothermodule-<=2.2.0,>=1.1.0',
                'module-version:themodule-==1.1.0'
            ])

        self.assertEqual(manifest.slots['slot2'].slot_key, 'slot2')
        self.assertListEqual(
            sorted(manifest.slots['slot2'].dependencies.keys()),
            ['module-version:anothermodule-<=2.2.0,>=1.1.0'])

        self.assertListEqual(sorted(manifest.dependencies.keys()), [
            'module-version:anothermodule-<=2.2.0,>=1.1.0',
            'module-version:themodule-==1.1.0'
        ])
        self.assertEqual(
            manifest.dependencies['module-version:themodule-==1.1.0'].
            dependency_id(), 'module-version:themodule-==1.1.0')
        self.assertEqual(manifest.created_at, creation_time)
        self.assertEqual(manifest.updated_at, updated_time)
Esempio n. 10
0
    def test_remove_slot(self, mocked_datetime):
        creation_time = datetime(2017, 1, 1, 2, 2, 2)
        mocked_datetime.utcnow.return_value = creation_time

        manifest = PackManifest(dependencies=self.dependencies,
                                slots=self.slots)

        # Remove slot1
        manifest.remove_slot('slot1')

        # Check that one dangling dependency was removed
        self.assertListEqual(sorted(manifest.slots.keys()), ['slot2'])
        self.assertListEqual(sorted(manifest.dependencies.keys()),
                             ['module-version:anothermodule-<=2.2.0,>=1.1.0'])

        # Remove slot2
        manifest.remove_slot('slot2')
        self.assertDictEqual(manifest.slots, {})
        self.assertDictEqual(manifest.dependencies, {})
Esempio n. 11
0
    def test_insert_slot(self):
        manifest = PackManifest()
        self.assertDictEqual(manifest.slots, {})
        self.assertDictEqual(manifest.dependencies, {})

        # Insert one slot
        manifest.insert_slot(self.slots_by_id['slot2'])

        self.assertListEqual(sorted(manifest.slots.keys()), ['slot2'])
        self.assertListEqual(sorted(manifest.dependencies.keys()),
                             ['module-version:anothermodule-<=2.2.0,>=1.1.0'])

        # Insert a second slot with common dependency
        manifest.insert_slot(self.slots_by_id['slot1'])

        self.assertListEqual(sorted(manifest.slots.keys()), ['slot1', 'slot2'])

        self.assertListEqual(sorted(manifest.dependencies.keys()), [
            'module-version:anothermodule-<=2.2.0,>=1.1.0',
            'module-version:themodule-==1.1.0'
        ])
Esempio n. 12
0
    def test_from_dict_wrong_slots_container(self):

        with self.assertRaises(MLIOPackWrongFormat):
            PackManifest.from_dict({'version': 2, 'slots': []})
Esempio n. 13
0
    def test_from_dict_wrong_version(self):

        with self.assertRaises(MLIOPackWrongFormat):
            PackManifest.from_dict({'version': 1})
Esempio n. 14
0
    def test_from_dict_bare_minimum(self):

        manifest = PackManifest.from_dict({'version': 2})
        self.assertDictEqual(manifest.slots, {})
        self.assertDictEqual(manifest.dependencies, {})
Esempio n. 15
0
    def test_remove_slot_invalid(self):
        manifest = PackManifest()

        with self.assertRaises(SlotKeyError):
            manifest.remove_slot('unknown')