Ejemplo n.º 1
0
    def test_merge_json_list(self):
        self.setUp()
        args = merge_json.parse_args([
            '-i',
            os.path.dirname(os.path.abspath(__file__)) + '/../test/test.json',
            os.path.dirname(os.path.abspath(__file__)) + '/../test/test.json',
            '-o',
            os.path.dirname(os.path.abspath(__file__)) +
            '/../test/output.json', '--jsonlist'
        ])
        merge_json.merge_json(args.output, args.inputs, args.jsonlist,
                              args.jsonload)
        #gotta compare line counts and not sizes.
        with open(
                os.path.dirname(os.path.abspath(__file__)) +
                '/../test/test.json') as f:
            original_count = sum(1 for _ in f)

        with open(
                os.path.dirname(os.path.abspath(__file__)) +
                '/../test/output.json') as f:
            json_list = json.load(f)
            new_count = len(json_list)
        #ouput should be the same number of lines as one input since the merge merges the same file with same object ids 2x.
        self.assertEqual(2 * original_count, new_count)
        #delete output.json when test is done
        self.tearDown()
Ejemplo n.º 2
0
    def test_merge_unique_json_load(self):
        self.setUp()
        args = merge_json.parse_args(
            [
                "-i",
                os.path.dirname(os.path.abspath(__file__)) + "/../test/test.one.json",
                os.path.dirname(os.path.abspath(__file__)) + "/../test/test.one.json",
                "-o",
                os.path.dirname(os.path.abspath(__file__)) + "/../test/output.json",
                "--jsonload",
                "-f",
                "_id",
            ]
        )
        merge_json.merge_json_unique(args.output, args.inputs, args.jsonlist, args.jsonload, args.uniquefield)
        # gotta compare line counts and not sizes.
        with open(os.path.dirname(os.path.abspath(__file__)) + "/../test/test.one.json") as f:
            original_count = sum(1 for _ in f)

        with open(os.path.dirname(os.path.abspath(__file__)) + "/../test/output.json") as f:
            new_count = sum(1 for _ in f)
        # ouput should be the same number of lines as one input since the merge merges the same file with same object ids 2x.
        self.assertEqual(original_count, new_count)
        # delete output.json when test is done
        self.tearDown()
Ejemplo n.º 3
0
 def test_merge_json_parse_args(self):
     args = merge_json.parse_args(["-i", "~/data1.json", "~/data2.json", "-o", "~/data3.json"])
     self.assertEqual(set(args.inputs), set(["~/data1.json", "~/data2.json"]))
     self.assertEqual(args.output, "~/data3.json")
Ejemplo n.º 4
0
 def test_merge_json_parse_args(self):
     args = merge_json.parse_args(
         ['-i', '~/data1.json', '~/data2.json', '-o', '~/data3.json'])
     self.assertEqual(set(args.inputs),
                      set(['~/data1.json', '~/data2.json']))
     self.assertEqual(args.output, '~/data3.json')