def test_excel_range_parser(self, ranges, expected_result):
     result = WorksheetData.parse_excel_notation(ranges)
     assert len(expected_result) == len(result)
     for match in range(len(expected_result)):
         for param in expected_result[match]:
             assert param in result[match] and result[match][
                 param] == expected_result[match][param]
    def test_worksheet_data_multiple_sheets(self, path, ranges, defined_names,
                                            expected_result_path):
        wb_path = os.path.join(os.path.dirname(__file__), path)
        wb = WorksheetData(
            wb_path, {
                "ranges":
                WorksheetData.parse_excel_notation(ranges),
                "named_ranges":
                WorksheetData.parse_defined_names_notation(defined_names)
            })
        wb.parse()
        res_path = os.path.join(os.path.dirname(__file__),
                                expected_result_path)
        with open(res_path, 'r') as file:
            expected = file.read()
        expected = json.loads(expected.strip())
        actual = json.loads(
            json.dumps(wb.result, default=WorksheetData.serializer))
        # Python 3.6 and 2.7 have different dictionary iteration order, so the _keys
        # are the same, but in different order
        expected["sheets"]["_keys"].sort()
        actual["sheets"]["_keys"].sort()

        expected = sort_json_arrays(expected)
        actual = sort_json_arrays(actual)
        assert expected == actual
 def test_no_arguments_fails(self, path, ranges, defined_names,
                             expected_result_path):
     # Test that wrong input raises a FunctionError
     with pytest.raises((FunctionException_, FunctionError_)):
         wb_path = os.path.join(os.path.dirname(__file__), path)
         wb = WorksheetData(
             wb_path, {
                 "ranges":
                 WorksheetData.parse_excel_notation(ranges),
                 "named_ranges":
                 WorksheetData.parse_defined_names_notation(defined_names)
             })
         wb.parse()
    def test_defined_ranges_different_inputs(self, path, ranges, defined_names,
                                             expected_result_path):
        wb_path = os.path.join(os.path.dirname(__file__), path)
        wb = WorksheetData(
            wb_path, {
                "ranges": WorksheetData.parse_excel_notation(ranges),
                "named_ranges": defined_names
            })
        wb.parse()
        res_path = os.path.join(os.path.dirname(__file__),
                                expected_result_path)
        with open(res_path, 'r') as file:
            expected = file.read()

        assert json.loads(expected.strip()) == json.loads(
            json.dumps(wb.result, default=WorksheetData.serializer))
 def test_worksheet_data_single_cell(self, path, ranges, defined_names,
                                     expected_result_path):
     wb_path = os.path.join(os.path.dirname(__file__), path)
     wb = WorksheetData(
         wb_path, {
             "ranges":
             WorksheetData.parse_excel_notation(ranges),
             "named_ranges":
             WorksheetData.parse_defined_names_notation(defined_names)
         })
     wb.parse()
     res_path = os.path.join(os.path.dirname(__file__),
                             expected_result_path)
     with open(res_path, 'r') as file:
         expected = file.read()
     # comparing objects is a work around for the difference in iteration through dictionaries in Python 2 and 3
     # which creates different json dumps
     assert json.loads(expected.strip()) == json.loads(
         json.dumps(wb.result, default=WorksheetData.serializer))
    def test_defined_names(self, path, ranges, defined_names,
                           expected_result_path):
        wb_path = os.path.join(os.path.dirname(__file__), path)
        wb = WorksheetData(
            wb_path, {
                "ranges":
                WorksheetData.parse_excel_notation(ranges),
                "named_ranges":
                WorksheetData.parse_defined_names_notation(defined_names)
            })
        wb.parse()
        res_path = os.path.join(os.path.dirname(__file__),
                                expected_result_path)
        with open(res_path, 'r') as file:
            expected = file.read()

        expected = sort_json_arrays(json.loads(expected.strip()))
        actual = sort_json_arrays(
            json.loads(json.dumps(wb.result,
                                  default=WorksheetData.serializer)))
        assert expected == actual