1+ import os
12import unittest
23from unittest .mock import mock_open , patch
34from data_scripts .structure_data import assign_link_lengths , create_network
@@ -14,7 +15,7 @@ def test_assign_link_lengths(self):
1415 """
1516 mock_file_content = "1\t 2\t 10\n 2\t 3\t 20\n "
1617 node_pairs_dict = {'1' : 'A' , '2' : 'B' , '3' : 'C' }
17- network_fp = " dummy/ path/ network.txt"
18+ network_fp = os . path . join ( ' dummy' , ' path' , ' network.txt' )
1819
1920 with patch ("builtins.open" , mock_open (read_data = mock_file_content )):
2021 response_dict = assign_link_lengths (network_fp = network_fp , node_pairs_dict = node_pairs_dict ,
@@ -35,21 +36,23 @@ def test_create_network(self, mock_assign_link_lengths):
3536 """
3637 mock_assign_link_lengths .return_value = {'link_lengths' : 'mocked' }
3738
39+ base_network_fp = os .path .join ('data' , 'raw' )
40+
3841 net_name = 'USNet'
3942 response = create_network (net_name = net_name , const_weight = False )
40- mock_assign_link_lengths .assert_called_with (constant_weight = False , network_fp = 'data \\ raw \\ us_network.txt' ,
43+ mock_assign_link_lengths .assert_called_with (constant_weight = False , network_fp = os . path . join ( base_network_fp , ' us_network.txt') ,
4144 node_pairs_dict = {})
4245 self .assertEqual (({'link_lengths' : 'mocked' }, []), response )
4346
4447 net_name = 'NSFNet'
4548 response = create_network (net_name = net_name , const_weight = False )
46- mock_assign_link_lengths .assert_called_with (constant_weight = False , network_fp = 'data \\ raw \\ nsf_network.txt' ,
49+ mock_assign_link_lengths .assert_called_with (constant_weight = False , network_fp = os . path . join ( base_network_fp , ' nsf_network.txt') ,
4750 node_pairs_dict = {})
4851 self .assertEqual (({'link_lengths' : 'mocked' }, []), response )
4952
5053 net_name = 'Pan-European'
5154 response = create_network (net_name = net_name , const_weight = False )
52- mock_assign_link_lengths .assert_called_with (constant_weight = False , network_fp = 'data \\ raw \\ europe_network.txt' ,
55+ mock_assign_link_lengths .assert_called_with (constant_weight = False , network_fp = os . path . join ( base_network_fp , ' europe_network.txt') ,
5356 node_pairs_dict = {})
5457 self .assertEqual (({'link_lengths' : 'mocked' }, []), response )
5558
@@ -60,14 +63,15 @@ def test_create_network_with_base_fp(self):
6063 """
6164 Test create network with base_fp specified.
6265 """
63- base_fp = 'custom\\ path'
66+ base_fp = os . path . join ( 'custom' , ' path')
6467 with patch ("data_scripts.structure_data.assign_link_lengths" ) as mock_assign_link_lengths :
6568 mock_assign_link_lengths .return_value = {'link_lengths' : 'mocked' }
6669
6770 net_name = 'USNet'
6871 response = create_network (net_name = net_name , base_fp = base_fp , const_weight = False )
72+ network_fp = os .path .join (base_fp , 'raw' , 'us_network.txt' )
6973 mock_assign_link_lengths .assert_called_with (constant_weight = False ,
70- network_fp = 'custom \\ path \\ raw \\ us_network.txt' , node_pairs_dict = {})
74+ network_fp = network_fp , node_pairs_dict = {})
7175 self .assertEqual (({'link_lengths' : 'mocked' }, []), response )
7276
7377
0 commit comments