Skip to content

Commit 621959f

Browse files
Use dynamic paths
Also fix failures for create network output. Input is usually the network name in the config while output is the returned .txt file.
1 parent 7063cec commit 621959f

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

data_scripts/structure_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def create_network(net_name: str, base_fp: str = None, const_weight: bool = Fals
5757
"""
5858
core_nodes_list = []
5959
if base_fp is None:
60-
base_fp = 'data\\raw'
60+
base_fp = os.path.join('data', 'raw')
6161
else:
6262
base_fp = os.path.join(base_fp, 'raw')
6363

tests/test_structure_data.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import unittest
23
from unittest.mock import mock_open, patch
34
from 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\t2\t10\n2\t3\t20\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

Comments
 (0)