Пример #1
0
    def test_complex_archiving_rerooting(self):
        """
        Tests the compand operation when source folder structure is reorganized in a complex way.
        Some subfolder into different level folders. """
        memory = io.BytesIO()

        instructions = [
            pony.pack('test/temp-data', 'test-data', '*.txt'),
            pony.pack('test/temp-data/subfolder/subsubfolder', 'moved-folder',
                      '*.txt')
        ]

        pony.gz_package(package_instructions=instructions, mem=memory)

        memory = io.BytesIO(memory.getvalue())
        instructions = [
            pony.unpack('test-data', 'test/results-data'),
            pony.unpack('moved-folder', 'test/results-data')
        ]
        pony.gz_unbox(unbox_instructions=instructions, mem=memory)

        self.assertTrue(os.path.exists('test/results-data/one.txt'))
        self.assertTrue(os.path.exists('test/results-data/two.txt'))
        self.assertTrue(
            os.path.exists('test/results-data/subfolder/three.txt'))
        self.assertTrue(os.path.exists('test/results-data/four.txt'))

        # it also has not extracted the rerooted elements into their original structure
        self.assertFalse(
            os.path.exists(
                'test/results-data/subfolder/subsubfolder/four.txt'))
        self.assertFalse(
            os.path.exists('test/results-data/subfolder/ignore.tx'))
    def test_deliver_op_fail_version_exact(self):
        """
        Test a fail case, it must raise NotInBag exception because
        there isn't a stored package with request metadata
        """

        instructions = [
            pony.unpack('test-data', 'test/results-data'),
            pony.unpack('moved-folder', 'test/results-data')
        ]

        meta_request = {"NAME": "dep-v1", "VERSION": "1.0.1"}
        with self.assertRaises(pony.bag.NotInBag):
            pony.deliver(instructions, meta_request)
    def test_deliver_op_version_greater(self):
        """
        Test a success case, it must successfully unbox a stored package
        with request metadata (version greater then)
        """

        instructions = [
            pony.unpack('test-data', 'test/results-data'),
            pony.unpack('moved-folder', 'test/results-data')
        ]

        meta_request = {"NAME": "dep-v1", "VERSION": {"$gte": "0.9.0"}}
        pony.deliver(instructions, meta_request)

        self.assertTrue(os.path.exists('test/results-data/one.txt'))
        self.assertTrue(os.path.exists('test/results-data/two.txt'))
        self.assertTrue(
            os.path.exists('test/results-data/subfolder/three.txt'))
    def test_deliver_op_version_greater_from_json(self):
        """
        Checks pony can deliver boxes based on json a requirement
        description (actually just a single requirement description)
        and the instructions for the unboxing.
        In this case the requireiment description is complex, it is like: version greater then...
        """
        import json
        json_string = """
        [
                {"NAME" : "dep-v1", "VERSION" :  {"$gte" : "0.9.0"} }
        ]"""
        meta_request = json.loads(json_string)

        instructions = [
            pony.unpack('test-data', 'test/results-data'),
            pony.unpack('moved-folder', 'test/results-data')
        ]

        requirements, gr = pony.deliver(instructions, meta_request[0])
        instructions = [
            pony.pack('test/temp-data', 'test-data', '*.txt'),
            pony.pack('test/temp-data/subfolder/subsubfolder', 'moved-folder',
                      '*.txt')
        ]
        self.assertTrue(os.path.exists('test/results-data/one.txt'))
        self.assertTrue(os.path.exists('test/results-data/two.txt'))
        self.assertTrue(
            os.path.exists('test/results-data/subfolder/three.txt'))

        # checks the log from the deliver operation. This will check the all compatible versions of dependencies are taken into account
        # and that only one is seleceted to resolve dependency.

        self.assertEqual("""digraph {
    "{ NAME:dep-v1, VERSION:1.0.0 }" [penwidth=3 color=blue ];
    "{ NAME:dep-v1, VERSION:1.1.0 }" [penwidth=3 ];

}
""",
                         to_dot_string(gr),
                         msg=to_dot_string(gr))
    def test_deliver_op_return_created_files(self):
        """
        Test a ssuccess case, it must successfully unbox a stored package
        with request metadata
        """

        instructions = [
            pony.unpack('test-data', 'test/results-data'),
            pony.unpack('moved-folder', 'test/results-data')
        ]
        meta_request = {"NAME": "prj61", "VERSION": "1.3.0"}
        created_files, dep_graph = pony.deliver(instructions, meta_request)

        for fname in [
                'test/results-data/one.txt', 'test/results-data/two.txt',
                'test/results-data/subfolder/three.txt'
        ]:
            self.assertTrue(fname in created_files,
                            msg=str(fname) + ' not in ' + str(created_files) +
                            '\nDependency graph is\n' +
                            to_dot_string(dep_graph))
Пример #6
0
    def test_file_exist_after_mem_compand(self):
        """
        Try to compress to an in-memory tarball storing test folder structure as a rerooted structure.
        then expand again in a different destination folder. 
        Apply a filter on archived files: take only .txt files. In fact skip ignore.tx"""
        memory = io.BytesIO()

        instruction = pony.pack('test/temp-data', 'test-data', '*.txt')
        pony.gz_package(package_instructions=[instruction], mem=memory)

        memory = io.BytesIO(memory.getvalue())
        instruction = pony.unpack('test-data', 'test/results-data')
        pony.gz_unbox(unbox_instructions=[instruction], mem=memory)

        self.assertTrue(os.path.exists('test/results-data/one.txt'))
        self.assertTrue(os.path.exists('test/results-data/two.txt'))
        self.assertTrue(
            os.path.exists('test/results-data/subfolder/three.txt'))
        self.assertTrue(
            os.path.exists(
                'test/results-data/subfolder/subsubfolder/four.txt'))

        self.assertFalse(
            os.path.exists('test/results-data/subfolder/ignore.tx'))
    def test_deliver_op_multiple_dependencies(self):
        """
        Checks can retrieve multiple dependencies using only one set of unpack instructions.

        Checks pony can deliver boxes based on json description of project dependencies metadata:
            - dependency metadata
            - unbox instructions

        In this case the requreiment description is complex, it is like: version greater then...
        In this case there are multiple acceptable dependency project version. Pony shall
        chose any of those and success.

        Checks also that the requirement graph constructed from json dependency description, is the same as the one contructed
        based on lower level dependency description (by means of python objects). 

        
        """

        import json
        json_string = """
        [
                {   "NAME" :  "dep-v1",
                    "VERSION" :  {"$gte" : "0.9.0"} 
                },

                {   "NAME"      : "prj61",
                    "VERSION"   : "1.3.0"
                }
        ]"""

        # construct the requirement description object from json and from python object.
        meta_request = json.loads(json_string)
        meta_request_raw = [{
            "NAME": "dep-v1",
            "VERSION": {
                "$gte": "0.9.0"
            }
        }, {
            "NAME": "prj61",
            "VERSION": "1.3.0"
        }]

        instructions = [
            pony.unpack('test-data', 'test/results-data'),
            pony.unpack('moved-folder', 'test/results-data')
        ]

        # ask pony to deliver dependencies as described from the requirements constructed from json and from raw python object.
        files, gr = pony.deliver(instructions, meta_request)
        files_raw, gr_raw = pony.deliver(instructions, meta_request_raw)

        fail_message = "The requirement graph constructed from json string is:\n" + to_dot_string(
            gr
        ) + "\nwhile the one constructed from equivalent python object is:\n" + to_dot_string(
            gr_raw)
        self.assertEqual(to_dot_string(gr),
                         to_dot_string(gr_raw),
                         msg=fail_message)

        self.assertTrue(os.path.exists('test/results-data/one.txt'))
        self.assertTrue(os.path.exists('test/results-data/two.txt'))
        self.assertTrue(
            os.path.exists('test/results-data/subfolder/three.txt'))