Commit 7b510d7b authored by mouadh's avatar mouadh

format

parent 1fc8aba4
CUBE = 'sales' CUBE = 'sales'
query1 = """SELECT query1 = """SELECT
......
import pandas as pd import pandas as pd
from olapy.core.mdx.executor.execute import MdxEngine from olapy.core.mdx.executor.execute import MdxEngine
...@@ -8,33 +7,49 @@ from tests.queries import query1, CUBE, query3, query6 ...@@ -8,33 +7,49 @@ from tests.queries import query1, CUBE, query3, query6
executer = MdxEngine(CUBE) executer = MdxEngine(CUBE)
def test_execution_query1(): def test_execution_query1():
executer.mdx_query = query1 executer.mdx_query = query1
assert executer.execute_mdx()['result']['Amount'][0] == 1023 assert executer.execute_mdx()['result']['Amount'][0] == 1023
def test_execution_query2(): def test_execution_query2():
executer.mdx_query = query3 executer.mdx_query = query3
df = executer.execute_mdx()['result'] df = executer.execute_mdx()['result']
test_df = pd.DataFrame( test_df = pd.DataFrame({
{'Country': ['France', 'Spain', 'Switzerland', 'United States'], 'Amount': [4, 3, 248, 768]}).groupby( 'Country': ['France', 'Spain', 'Switzerland', 'United States'],
['Country']).sum() 'Amount': [4, 3, 248, 768]
}).groupby(['Country']).sum()
assert assert_frame_equal(df, test_df) is None
assert assert_frame_equal(df,test_df) is None
def test_execution_query6(): def test_execution_query6():
executer.mdx_query = query6 executer.mdx_query = query6
df = executer.execute_mdx()['result'] df = executer.execute_mdx()['result']
test_df = pd.DataFrame( test_df = pd.DataFrame({
{'Year': [2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010], 'Year': [
'Quarter': [-1, 'Q2 2010', 'Q2 2010', 'Q2 2010', 'Q2 2010', 'Q2 2010', 'Q2 2010', 'Q2 2010', 'Q2 2010', 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010,
'Q2 2010', 'Q2 2010', 'Q2 2010', 'Q2 2010'], 2010, 2010
'Month': [-1, -1, 'May 2010', 'May 2010', 'May 2010', 'May 2010', 'May 2010', 'May 2010', 'May 2010', ],
'May 2010', 'May 2010', 'May 2010', 'May 2010'], 'Quarter': [
'Day': [-1, -1, -1, 'May 12,2010', 'May 13,2010', 'May 14,2010', 'May 15,2010', 'May 16,2010', 'May 17,2010', -1, 'Q2 2010', 'Q2 2010', 'Q2 2010', 'Q2 2010', 'Q2 2010',
'May 18,2010', 'May 19,2010', 'May 20,2010', 'May 21,2010'], 'Q2 2010', 'Q2 2010', 'Q2 2010', 'Q2 2010', 'Q2 2010', 'Q2 2010',
'Amount': [1023, 1023, 1023, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512]}).groupby( 'Q2 2010'
['Year', 'Quarter', 'Month', 'Day']).sum() ],
'Month': [
-1, -1, 'May 2010', 'May 2010', 'May 2010', 'May 2010', 'May 2010',
'May 2010', 'May 2010', 'May 2010', 'May 2010', 'May 2010',
'May 2010'
],
'Day': [
-1, -1, -1, 'May 12,2010', 'May 13,2010', 'May 14,2010',
'May 15,2010', 'May 16,2010', 'May 17,2010', 'May 18,2010',
'May 19,2010', 'May 20,2010', 'May 21,2010'
],
'Amount': [1023, 1023, 1023, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
}).groupby(['Year', 'Quarter', 'Month', 'Day']).sum()
assert assert_frame_equal(df, test_df) is None assert assert_frame_equal(df, test_df) is None
...@@ -16,7 +16,8 @@ def test_parsing_query1(): ...@@ -16,7 +16,8 @@ def test_parsing_query1():
query_parts = executer.decorticate_query(query1 + '\n' + where) query_parts = executer.decorticate_query(query1 + '\n' + where)
assert query_parts['all'] == [['Measures', 'Amount'], ['Time', 'Calendar', 'Day', 'May 12,2010']] assert query_parts['all'] == [['Measures', 'Amount'],
['Time', 'Calendar', 'Day', 'May 12,2010']]
assert query_parts['rows'] == [] assert query_parts['rows'] == []
assert query_parts['where'] == [['Time', 'Calendar', 'Day', 'May 12,2010']] assert query_parts['where'] == [['Time', 'Calendar', 'Day', 'May 12,2010']]
assert query_parts['columns'] == [['Measures', 'Amount']] assert query_parts['columns'] == [['Measures', 'Amount']]
...@@ -32,7 +33,8 @@ def test_parsing_query2(): ...@@ -32,7 +33,8 @@ def test_parsing_query2():
query_parts = executer.decorticate_query(query2 + '\n' + where) query_parts = executer.decorticate_query(query2 + '\n' + where)
assert query_parts['all'] == [['Geography', 'Economy', 'Partnership'], ['Time', 'Calendar', 'Day', 'May 12,2010']] assert query_parts['all'] == [['Geography', 'Economy', 'Partnership'],
['Time', 'Calendar', 'Day', 'May 12,2010']]
assert query_parts['rows'] == [] assert query_parts['rows'] == []
assert query_parts['where'] == [['Time', 'Calendar', 'Day', 'May 12,2010']] assert query_parts['where'] == [['Time', 'Calendar', 'Day', 'May 12,2010']]
assert query_parts['columns'] == [['Geography', 'Economy', 'Partnership']] assert query_parts['columns'] == [['Geography', 'Economy', 'Partnership']]
...@@ -41,14 +43,16 @@ def test_parsing_query2(): ...@@ -41,14 +43,16 @@ def test_parsing_query2():
def test_parsing_query3(): def test_parsing_query3():
query_parts = executer.decorticate_query(query3) query_parts = executer.decorticate_query(query3)
assert query_parts['all'] == [['Geography', 'Geo', 'Country'], ['Measures', 'Amount']] assert query_parts['all'] == [['Geography', 'Geo', 'Country'],
['Measures', 'Amount']]
assert query_parts['rows'] == [['Measures', 'Amount']] assert query_parts['rows'] == [['Measures', 'Amount']]
assert query_parts['where'] == [] assert query_parts['where'] == []
assert query_parts['columns'] == [['Geography', 'Geo', 'Country']] assert query_parts['columns'] == [['Geography', 'Geo', 'Country']]
query_parts = executer.decorticate_query(query3 + '\n' + where) query_parts = executer.decorticate_query(query3 + '\n' + where)
assert query_parts['all'] == [['Geography', 'Geo', 'Country'], ['Measures', 'Amount'], assert query_parts['all'] == [['Geography', 'Geo',
'Country'], ['Measures', 'Amount'],
['Time', 'Calendar', 'Day', 'May 12,2010']] ['Time', 'Calendar', 'Day', 'May 12,2010']]
assert query_parts['rows'] == [['Measures', 'Amount']] assert query_parts['rows'] == [['Measures', 'Amount']]
assert query_parts['where'] == [['Time', 'Calendar', 'Day', 'May 12,2010']] assert query_parts['where'] == [['Time', 'Calendar', 'Day', 'May 12,2010']]
...@@ -58,14 +62,16 @@ def test_parsing_query3(): ...@@ -58,14 +62,16 @@ def test_parsing_query3():
def test_parsing_query4(): def test_parsing_query4():
query_parts = executer.decorticate_query(query4) query_parts = executer.decorticate_query(query4)
assert query_parts['all'] == [['Geography', 'Economy', 'Partnership'], ['Geography', 'Geo', 'Country']] assert query_parts['all'] == [['Geography', 'Economy', 'Partnership'],
['Geography', 'Geo', 'Country']]
assert query_parts['rows'] == [['Geography', 'Geo', 'Country']] assert query_parts['rows'] == [['Geography', 'Geo', 'Country']]
assert query_parts['where'] == [] assert query_parts['where'] == []
assert query_parts['columns'] == [['Geography', 'Economy', 'Partnership']] assert query_parts['columns'] == [['Geography', 'Economy', 'Partnership']]
query_parts = executer.decorticate_query(query4 + '\n' + where) query_parts = executer.decorticate_query(query4 + '\n' + where)
assert query_parts['all'] == [['Geography', 'Economy', 'Partnership'], ['Geography', 'Geo', 'Country'], assert query_parts['all'] == [['Geography', 'Economy', 'Partnership'],
['Geography', 'Geo', 'Country'],
['Time', 'Calendar', 'Day', 'May 12,2010']] ['Time', 'Calendar', 'Day', 'May 12,2010']]
assert query_parts['rows'] == [['Geography', 'Geo', 'Country']] assert query_parts['rows'] == [['Geography', 'Geo', 'Country']]
assert query_parts['where'] == [['Time', 'Calendar', 'Day', 'May 12,2010']] assert query_parts['where'] == [['Time', 'Calendar', 'Day', 'May 12,2010']]
...@@ -75,42 +81,48 @@ def test_parsing_query4(): ...@@ -75,42 +81,48 @@ def test_parsing_query4():
def test_parsing_query5(): def test_parsing_query5():
query_parts = executer.decorticate_query(query5) query_parts = executer.decorticate_query(query5)
assert query_parts['all'] == [['Geography', 'Economy', 'Partnership', 'EU'], assert query_parts['all'] == [[
['Geography', 'Economy', 'Partnership', 'None'], 'Geography', 'Economy', 'Partnership', 'EU'
['Geography', 'Economy', 'Partnership', 'NAFTA'], ], ['Geography', 'Economy', 'Partnership', 'None'], [
['Product', 'Prod', 'Company', 'Crazy Development'], 'Geography', 'Economy', 'Partnership', 'NAFTA'
['Product', 'Prod', 'Company', 'Company_test'], ], ['Product', 'Prod', 'Company', 'Crazy Development'], [
['Product', 'Prod', 'Company', 'test_Development']] 'Product', 'Prod', 'Company', 'Company_test'
], ['Product', 'Prod', 'Company', 'test_Development']]
assert query_parts['rows'] == [['Product', 'Prod', 'Company', 'Crazy Development'], assert query_parts['rows'] == [[
['Product', 'Prod', 'Company', 'Company_test'], 'Product', 'Prod', 'Company', 'Crazy Development'
['Product', 'Prod', 'Company', 'test_Development']] ], ['Product', 'Prod', 'Company',
'Company_test'], ['Product', 'Prod', 'Company', 'test_Development']]
assert query_parts['where'] == [] assert query_parts['where'] == []
assert query_parts['columns'] == [['Geography', 'Economy', 'Partnership', 'EU'], assert query_parts['columns'] == [[
['Geography', 'Economy', 'Partnership', 'None'], 'Geography', 'Economy', 'Partnership', 'EU'
['Geography', 'Economy', 'Partnership', 'NAFTA']] ], ['Geography', 'Economy', 'Partnership',
'None'], ['Geography', 'Economy', 'Partnership', 'NAFTA']]
query_parts = executer.decorticate_query(query5 + '\n' + where) query_parts = executer.decorticate_query(query5 + '\n' + where)
assert query_parts['all'] == [['Geography', 'Economy', 'Partnership', 'EU'], assert query_parts['all'] == [[
['Geography', 'Economy', 'Partnership', 'None'], 'Geography', 'Economy', 'Partnership', 'EU'
['Geography', 'Economy', 'Partnership', 'NAFTA'], ], ['Geography', 'Economy', 'Partnership', 'None'], [
['Product', 'Prod', 'Company', 'Crazy Development'], 'Geography', 'Economy', 'Partnership', 'NAFTA'
['Product', 'Prod', 'Company', 'Company_test'], ], ['Product', 'Prod', 'Company', 'Crazy Development'], [
['Product', 'Prod', 'Company', 'test_Development'], 'Product', 'Prod', 'Company', 'Company_test'
], ['Product', 'Prod', 'Company', 'test_Development'],
['Time', 'Calendar', 'Day', 'May 12,2010']] ['Time', 'Calendar', 'Day', 'May 12,2010']]
assert query_parts['rows'] == [['Product', 'Prod', 'Company', 'Crazy Development'], assert query_parts['rows'] == [[
['Product', 'Prod', 'Company', 'Company_test'], 'Product', 'Prod', 'Company', 'Crazy Development'
['Product', 'Prod', 'Company', 'test_Development']] ], ['Product', 'Prod', 'Company',
'Company_test'], ['Product', 'Prod', 'Company', 'test_Development']]
assert query_parts['where'] == [['Time', 'Calendar', 'Day', 'May 12,2010']] assert query_parts['where'] == [['Time', 'Calendar', 'Day', 'May 12,2010']]
assert query_parts['columns'] == [['Geography', 'Economy', 'Partnership', 'EU'], assert query_parts['columns'] == [[
['Geography', 'Economy', 'Partnership', 'None'], 'Geography', 'Economy', 'Partnership', 'EU'
['Geography', 'Economy', 'Partnership', 'NAFTA']] ], ['Geography', 'Economy', 'Partnership',
'None'], ['Geography', 'Economy', 'Partnership', 'NAFTA']]
def test_parsing_query6(): def test_parsing_query6():
...@@ -119,24 +131,28 @@ def test_parsing_query6(): ...@@ -119,24 +131,28 @@ def test_parsing_query6():
query_parts = executer.decorticate_query(query6) query_parts = executer.decorticate_query(query6)
assert query_parts['all'] == [['Time', 'Time', 'Year'], ['Time', 'Time', 'Year', '2010'], assert query_parts['all'] == [['Time', 'Time', 'Year'], [
['Time', 'Time', 'Quarter', '2010', 'Q2 2010'], 'Time', 'Time', 'Year', '2010'
['Time', 'Time', 'Month', '2010', 'Q2 2010', 'May 2010'], ], ['Time', 'Time', 'Quarter', '2010',
'Q2 2010'], ['Time', 'Time', 'Month', '2010', 'Q2 2010', 'May 2010'],
['Measures', 'Amount']] ['Measures', 'Amount']]
assert query_parts['rows'] == [] assert query_parts['rows'] == []
assert query_parts['where'] == [['Measures', 'Amount']] assert query_parts['where'] == [['Measures', 'Amount']]
assert query_parts['columns'] == [['Time', 'Time', 'Year'], ['Time', 'Time', 'Year', '2010'], assert query_parts['columns'] == [['Time', 'Time', 'Year'], [
['Time', 'Time', 'Quarter', '2010', 'Q2 2010'], 'Time', 'Time', 'Year', '2010'
['Time', 'Time', 'Month', '2010', 'Q2 2010', 'May 2010']] ], ['Time', 'Time', 'Quarter', '2010',
'Q2 2010'], ['Time', 'Time', 'Month', '2010', 'Q2 2010', 'May 2010']]
query_parts = executer.decorticate_query(query6 + '\n' + where) query_parts = executer.decorticate_query(query6 + '\n' + where)
assert query_parts['all'] == [['Time', 'Time', 'Year'], ['Time', 'Time', 'Year', '2010'], assert query_parts['all'] == [['Time', 'Time', 'Year'], [
['Time', 'Time', 'Quarter', '2010', 'Q2 2010'], 'Time', 'Time', 'Year', '2010'
['Time', 'Time', 'Month', '2010', 'Q2 2010', 'May 2010'], ['Measures', 'Amount'], ], ['Time', 'Time', 'Quarter', '2010',
'Q2 2010'], ['Time', 'Time', 'Month', '2010', 'Q2 2010',
'May 2010'], ['Measures', 'Amount'],
['Time', 'Calendar', 'Day', 'May 12,2010']] ['Time', 'Calendar', 'Day', 'May 12,2010']]
assert query_parts['rows'] == [] assert query_parts['rows'] == []
...@@ -144,7 +160,7 @@ def test_parsing_query6(): ...@@ -144,7 +160,7 @@ def test_parsing_query6():
assert query_parts['where'] == [['Measures', 'Amount'], assert query_parts['where'] == [['Measures', 'Amount'],
['Time', 'Calendar', 'Day', 'May 12,2010']] ['Time', 'Calendar', 'Day', 'May 12,2010']]
assert query_parts['columns'] == [['Time', 'Time', 'Year'], ['Time', 'Time', 'Year', '2010'], assert query_parts['columns'] == [['Time', 'Time', 'Year'], [
['Time', 'Time', 'Quarter', '2010', 'Q2 2010'], 'Time', 'Time', 'Year', '2010'
['Time', 'Time', 'Month', '2010', 'Q2 2010', 'May 2010']] ], ['Time', 'Time', 'Quarter', '2010',
'Q2 2010'], ['Time', 'Time', 'Month', '2010', 'Q2 2010', 'May 2010']]
...@@ -50,7 +50,8 @@ class WSGIServer: ...@@ -50,7 +50,8 @@ class WSGIServer:
Copy/pasted from pytest_localserver w/ slight changes. Copy/pasted from pytest_localserver w/ slight changes.
""" """
def __init__(self, host='127.0.0.1', port=8000, application=None, **kwargs): def __init__(self, host='127.0.0.1', port=8000, application=None,
**kwargs):
self._server = make_server(host, port, application, **kwargs) self._server = make_server(host, port, application, **kwargs)
self.server_address = self._server.server_address self.server_address = self._server.server_address
...@@ -197,7 +198,8 @@ def test_query2(conn): ...@@ -197,7 +198,8 @@ def test_query2(conn):
mems.append( mems.append(
Member( Member(
_Hierarchy='[Geography].[Geography]', _Hierarchy='[Geography].[Geography]',
UName='[Geography].[Geography].[Country].[America].[United States]', UName=
'[Geography].[Geography].[Country].[America].[United States]',
Caption='United States', Caption='United States',
LName='[Geography].[Geography].[Country]', LName='[Geography].[Geography].[Country]',
LNum='1', LNum='1',
...@@ -207,12 +209,14 @@ def test_query2(conn): ...@@ -207,12 +209,14 @@ def test_query2(conn):
mems.append( mems.append(
Member( Member(
_Hierarchy='[Geography].[Geography]', _Hierarchy='[Geography].[Geography]',
UName='[Geography].[Geography].[City].[America].[United States].[New York]', UName=
'[Geography].[Geography].[City].[America].[United States].[New York]',
Caption='New York', Caption='New York',
LName='[Geography].[Geography].[City]', LName='[Geography].[Geography].[City]',
LNum='2', LNum='2',
DisplayInfo='131076', DisplayInfo='131076',
PARENT_UNIQUE_NAME='[Geography].[Geography].[Continent].[America].[United States]', PARENT_UNIQUE_NAME=
'[Geography].[Geography].[Continent].[America].[United States]',
HIERARCHY_UNIQUE_NAME='[Geography].[Geography]')) HIERARCHY_UNIQUE_NAME='[Geography].[Geography]'))
mems.append( mems.append(
Member( Member(
...@@ -246,12 +250,14 @@ def test_query2(conn): ...@@ -246,12 +250,14 @@ def test_query2(conn):
mems.append( mems.append(
Member( Member(
_Hierarchy='[Geography].[Geography]', _Hierarchy='[Geography].[Geography]',
UName='[Geography].[Geography].[City].[Europe].[Spain].[Barcelona]', UName=
'[Geography].[Geography].[City].[Europe].[Spain].[Barcelona]',
Caption='Barcelona', Caption='Barcelona',
LName='[Geography].[Geography].[City]', LName='[Geography].[Geography].[City]',
LNum='2', LNum='2',
DisplayInfo='131076', DisplayInfo='131076',
PARENT_UNIQUE_NAME='[Geography].[Geography].[Continent].[Europe].[Spain]', PARENT_UNIQUE_NAME=
'[Geography].[Geography].[Continent].[Europe].[Spain]',
HIERARCHY_UNIQUE_NAME='[Geography].[Geography]')) HIERARCHY_UNIQUE_NAME='[Geography].[Geography]'))
mems.append( mems.append(
Member( Member(
...@@ -261,7 +267,8 @@ def test_query2(conn): ...@@ -261,7 +267,8 @@ def test_query2(conn):
LName='[Geography].[Geography].[City]', LName='[Geography].[Geography].[City]',
LNum='2', LNum='2',
DisplayInfo='131076', DisplayInfo='131076',
PARENT_UNIQUE_NAME='[Geography].[Geography].[Continent].[Europe].[Spain]', PARENT_UNIQUE_NAME=
'[Geography].[Geography].[Continent].[Europe].[Spain]',
HIERARCHY_UNIQUE_NAME='[Geography].[Geography]')) HIERARCHY_UNIQUE_NAME='[Geography].[Geography]'))
mems.append( mems.append(
Member( Member(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment