def test_NMF_complex(): n_samples = 10 n_features = 20 n_components = 3 W = randn_complex(n_samples, n_components) H = np.random.rand(n_components, n_features) + 0j # Normalise H Hnorm = np.linalg.norm(H, axis=1) H /= Hnorm[:, None] # Normalise W then order Wnorm = np.linalg.norm(W, axis=0) W *= np.arange(n_components, 0, -1) / Wnorm X = np.dot(W, H) p = nmf.PinvNMF(n_components, nmf.ComplexMFConstraint(), max_iter=1000, initialiser=nmf.NMR_svd_initialise) Wcalc = p.fit_transform(X) Hcalc = p.components_ Xcalc = np.dot(Wcalc, Hcalc) # Check properties of Hcalc and Wcalc assert_sequence_equal(Wcalc.shape, (n_samples, n_components)) assert_sequence_equal(Hcalc.shape, (n_components, n_features)) assert_array_less(MAX_NEGATIVE_FLOAT, Hcalc.real) # Hcalc >= 0 assert_array_equal(0, Hcalc.imag) # Hcalc >= 0 # Check that Hcalc is normalised assert_array_almost_equal(np.linalg.norm(Hcalc, axis=1), 1) # N.B. Hcalc is not orthogonal so can't assert H.H' == I assert_array_almost_equal(X, Xcalc, decimal=3)
def test_manual_add_line(self): s = self.signal s.add_xray_lines_markers(['Zn_La']) nt.assert_sequence_equal(list(s._xray_markers.keys()), ['Zn_La']) nt.assert_equal(len(s._xray_markers), 1) # Check that the line has both a vertical line marker and text marker: nt.assert_equal(len(s._xray_markers['Zn_La']), 2)
def test_NMF_real(): n_samples = 10 n_features = 20 n_components = 3 W = np.random.rand(n_samples, n_components) H = np.random.rand(n_components, n_features) # Normalise H Hnorm = np.linalg.norm(H, axis=1) H /= Hnorm[:, None] # Normalise U then order Wnorm = np.linalg.norm(W, axis=0) W *= np.arange(n_components, 0, -1) / Wnorm X = np.dot(W, H) assert_array_less(0, X) # X is strictly greater than 0 p = nmf.NMF(n_components, tol=1e-5, max_iter=1000) Wcalc = p.fit_transform(X) Hcalc = p.components_ Xcalc = np.dot(Wcalc, Hcalc) # Check properties of Hcalc and Wcalc assert_sequence_equal(Wcalc.shape, (n_samples, n_components)) assert_sequence_equal(Hcalc.shape, (n_components, n_features)) assert_array_less(MAX_NEGATIVE_FLOAT, Wcalc) # Wcalc >= 0 assert_array_less(MAX_NEGATIVE_FLOAT, Hcalc) # Hcalc >= 0 assert_array_almost_equal(X, Xcalc, decimal=3)
def test_plot_auto_add(self): s = self.signal s.plot(xray_lines=True) # Should contain 6 lines nt.assert_sequence_equal( sorted(s._xray_markers.keys()), ['Al_Ka', 'Al_Kb', 'Zn_Ka', 'Zn_Kb', 'Zn_La', 'Zn_Lb1'])
def test_NMF_real_normalised(): n_samples = 10 n_features = 20 n_components = 3 W = np.random.rand(n_samples, n_components) H = np.random.rand(n_components, n_features) # Normalise H Hnorm = np.linalg.norm(H, axis=1) H /= Hnorm[:, None] # Normalise U then order Wnorm = np.linalg.norm(W, axis=0) W *= np.arange(n_components, 0, -1) / Wnorm X = np.dot(W, H) assert_array_less(0, X) # X is strictly greater than 0 p = nmf.ProjectedGradientNMF(n_components, nmf.NMFConstraint_NormaliseH(), max_iter=1000) Wcalc = p.fit_transform(X) Hcalc = p.components_ Xcalc = np.dot(Wcalc, Hcalc) # Check properties of Hcalc and Wcalc assert_sequence_equal(Wcalc.shape, (n_samples, n_components)) assert_sequence_equal(Hcalc.shape, (n_components, n_features)) assert_array_less(MAX_NEGATIVE_FLOAT, Wcalc) # Wcalc >= 0 assert_array_less(MAX_NEGATIVE_FLOAT, Hcalc) # Hcalc >= 0 # Check that Hcalc is normalised assert_array_almost_equal(np.linalg.norm(Hcalc, axis=1), 1) # N.B. Hcalc is not orthogonal so can't assert H.H' == I assert_array_almost_equal(X, Xcalc, decimal=3)
def t(self, key): s = '%(' + key + ')s' fmt = M.FormatString(s) assert_equal(len(fmt), 1) assert_sequence_equal(fmt.seq_arguments, []) [pkey] = fmt.map_arguments.keys() assert_equal(key, pkey)
def test_manual_add_line(self): s = self.signal s.add_xray_lines_markers(["Zn_La"]) nt.assert_sequence_equal(list(s._xray_markers.keys()), ["Zn_La"]) nt.assert_equal(len(s._xray_markers), 1) # Check that the line has both a vertical line marker and text marker: nt.assert_equal(len(s._xray_markers["Zn_La"]), 2)
def test_manual_remove_element(self): s = self.signal s.add_xray_lines_markers(['Zn_Ka', 'Zn_Kb', 'Zn_La']) s.remove_xray_lines_markers(['Zn_Kb']) nt.assert_sequence_equal( sorted(s._xray_markers.keys()), ['Zn_Ka', 'Zn_La'])
def test_group_name_multiple_ports(self): expected = [ Rule(protocol="tcp", from_port=22, to_port=22, security_group_name="default"), Rule(protocol="tcp", from_port=2812, to_port=2812, security_group_name="default"), Rule(protocol="tcp", from_port=4001, to_port=4001, security_group_name="default"), ] assert_sequence_equal(expected, RuleParser.parse("tcp port 22, 2812, 4001 default"))
def test_metric_names_match_list(): with open("test/neuron.swc", "rt") as fp: data = fp.read() out, err = command.run_lmeasure(data, *lm_metrics) command.check_errors(err) result = tuple(command.parse_results(out)) assert_sequence_equal([x['metric'] for x in result], lm_metrics)
def test_map_multiport(): actor_class = ConstructorWrapper(FuncActor, swap, inports=('a', 'b'), outports=('a', 'b')) amap = Map(actor_class, scheduler=LinearizedScheduler()) inputs = dict(a=[1, 2], b=[10, 20]) res = amap(**inputs) print(res) assert_sequence_equal(res['a'], inputs['b'])
def t(s, expected): fmt = M.FormatString(s) assert_equal(len(fmt), 1) if expected: assert_sequence_equal(fmt.warnings, []) else: [exc] = fmt.warnings assert_is_instance(exc, M.RedundantFlag)
def test_icmp(self): expected = [ Rule(protocol="icmp", from_port=0, to_port=0, security_group_name="default"), Rule(protocol="icmp", from_port=3, to_port=5, security_group_name="default"), Rule(protocol="icmp", from_port=8, to_port=14, security_group_name="default"), Rule(protocol="icmp", from_port=40, to_port=40, security_group_name="default") ] assert_sequence_equal(expected, RuleParser.parse("icmp port 0, 3-5, 8-14, 40 default"))
def check_signal(data, signal): assert_equals(signal.units, data.units) assert_sequence_equal(signal.shape, data.shape) assert_true(np.all(np.asarray(signal) == np.asarray(data))) try: assert_equals(signal.sampling_rate, data.sampling_rates[0]) except AttributeError: pass
def testEventsList(): assert_sequence_equal( map(lambda x: (x['name'], x['status']), form.Event.get_events_list()), [('testEventsList2', 1), ('testEventsList1', 0), ('testEventsList0', -1)]) assert_sequence_equal( map(lambda x: x['name'], form.Event.get_events_list(2, 1)), ['testEventsList0'])
def check_correct(expected, actual): assert expected.viewkeys() <= actual.viewkeys(), 'Different keys\nexpected\t{}\nactual\t{}'.format(sorted(expected.keys()), sorted(actual.keys())) for k in expected: exp = expected[k] act = actual[k] if hasattr(exp, '__iter__') and not hasattr(exp, 'items'): assert_sequence_equal(exp, act, 'Different on key "{}".\nexpected\t{}\nactual\t{}'.format(k, exp, act)) else: assert exp == act, 'Different on key "{}".\nexpected\t{}\nactual\t{}'.format(k, exp, act) return True
def test_geolocate_pass(): with open(os.path.join(os.path.dirname(__file__), 'fixtures', 'random_coordinate_pairs.yaml')) as fixtures_file: fixtures = yaml.load(fixtures_file) for fixture in fixtures: test_name = fixture['start_nom'] test_location = fixture.pop('start_loc') return_geocoder = [geopy.Location(test_name, test_location)] with mock.patch('geopy.geocoders.GoogleV3.geocode') as mock_geocoder: mock_geocoder.return_value = return_geocoder given_loc = Greengraph('first', 'second').geolocate(test_name) mock_geocoder.assert_any_call(test_name, exactly_one=False) assert_sequence_equal(test_location, given_loc)
def test_stdin_nonicks(self): command = loadscores.Command() command.stdin = StringIO(INPUT) self.execute(command, include_nicknames=False) tools.eq_(command.stdout.read(), "Header is:\n\t{}\n".format(HEADER)) tools.eq_(command.stderr.read(), "") tools.assert_sequence_equal(sorted(fulldocs(StateNameVoter.items.all())), [ {'state_lname_fname': 'NH_BULLWINKLE_BORIS', 'gotv_score': Decimal('-0.009')}, {'state_lname_fname': 'NH_BEARINGTON_JAMES', 'gotv_score': Decimal('-0.1'), 'persuasion_score': Decimal('4.8')}, {'state_lname_fname': 'NH_BEARINGTON_JOHN', 'gotv_score': Decimal('-0.007'), 'persuasion_score': Decimal('4.61')}, {'state_lname_fname': 'NH_ZIP_JOE', 'persuasion_score': Decimal('0'), 'gotv_score': Decimal('0')}, {'state_lname_fname': 'MN_STANTON_JANE', 'gotv_score': Decimal('0.003'), 'persuasion_score': Decimal('4.1')}, {'state_lname_fname': 'NH_ZIP_JOSEPH', 'persuasion_score': Decimal('3.1'), 'gotv_score': Decimal('0.2')}, ]) tools.assert_sequence_equal(sorted(fulldocs(StateCityNameVoter.items.all())), [ {'state_city_lname_fname': 'NH_SEABROOK_BULLWINKLE_BORIS', 'gotv_score': Decimal('-0.009')}, {'state_city_lname_fname': 'NH_ST-PAUL_BEARINGTON_JAMES', 'gotv_score': Decimal('-0.1'), 'persuasion_score': Decimal('4.8')}, {'state_city_lname_fname': 'NH_MILTON_BEARINGTON_JOHN', 'gotv_score': Decimal('-0.007'), 'persuasion_score': Decimal('4.61')}, {'state_city_lname_fname': 'NH_LEBANON_ZIP_JOE', 'persuasion_score': Decimal('0'), 'gotv_score': Decimal('0')}, {'state_city_lname_fname': 'MN_ST-PAUL_STANTON_JANE', 'gotv_score': Decimal('0.003'), 'persuasion_score': Decimal('4.88')}, {'state_city_lname_fname': 'MN_BLAINE_STANTON_JANE', 'gotv_score': Decimal('0.005'), 'persuasion_score': Decimal('4.1')}, {'state_city_lname_fname': 'NH_LEBANON_ZIP_JOSEPH', 'persuasion_score': Decimal('3.1'), 'gotv_score': Decimal('0.2')}, ])
def test_gen_raw_ch(): """Test that _generate_raw responds to channel settings.""" raw = _generate_raw(duration=1, n_chan=1) assert_sequence_equal(raw.ch_names, ['0', 'STI 014']) raw = _generate_raw(duration=1, n_chan=1, ch_names=['bob']) assert_sequence_equal(raw.ch_names, ['bob', 'STI 014']) raw = _generate_raw(duration=1, n_chan=1, ch_names='standard_1020') montage = read_montage('standard_1020') raw = raw.pick_types(eeg=True) assert_true(np.all([ch in montage.ch_names for ch in raw.ch_names]))
def test_PCA_complex(): n_samples = 10 n_features = 20 n_components = 3 U = randn_complex(n_samples, n_components) V = randn_complex(n_components, n_features) # Make V orthonormal for i in range(n_components): for j in range(i): i_dot_j = np.dot(V[i, :], V[j, :]) # N.B. V_j is already normalised V[i, :] -= i_dot_j * V[j, :] Vmean = np.mean(V[i, :]) V[i, :] -= Vmean Vnorm = np.linalg.norm(V[i, :]) V[i, :] /= Vnorm # Make U orthonormal, then multiply to get ordering of components for i in range(n_components): for j in range(i): i_dot_j = np.dot(U[:, i], U[:, j]) # N.B. U_j is already normalised U[:, i] -= i_dot_j * U[:, j] Umean = np.mean(U[:, i]) U[:, i] -= Umean Unorm = np.linalg.norm(U[:, i]) U[:, i] /= Unorm # ensure ordering U[:, i] *= (n_components - i) X = np.dot(U, V) assert_almost_equal(0, np.mean(X)) p = pca.PCA(n_components) Ucalc = p.fit_transform(X) Vcalc = p.components_ Xcalc = np.dot(Ucalc, Vcalc) # Check properties of Vcalc and Ucalc assert_sequence_equal(Ucalc.shape, U.shape) assert_sequence_equal(Vcalc.shape, V.shape) assert_array_almost_equal(np.eye(n_components), np.dot(Vcalc, np.conj(Vcalc.T))) assert_almost_diagonal(np.dot(np.conj(Ucalc.T), Ucalc), assert_real=True) # assert_array_almost_equal(np.diag(np.arange(n_components, 0, -1) ** 2), # np.dot(Ucalc.T, Ucalc)) assert_array_almost_equal(X, Xcalc)
def test_pandas_iterable(): try: import pandas as pd except ImportError: raise SkipTest("Pandas not installed") # Using a list or series yields equivalent # color maps, i.e the series isn't seen as # a single color lst = ['red', 'blue', 'green'] s = pd.Series(lst) cm1 = mcolors.ListedColormap(lst, N=5) cm2 = mcolors.ListedColormap(s, N=5) assert_sequence_equal(cm1.colors, cm2.colors)
def test_pandas_iterable(): try: import pandas as pd except ImportError: raise SkipTest("Pandas not installed") if assert_sequence_equal is None: raise SkipTest("nose lacks required function") # Using a list or series yields equivalent # color maps, i.e the series isn't seen as # a single color lst = ["red", "blue", "green"] s = pd.Series(lst) cm1 = mcolors.ListedColormap(lst, N=5) cm2 = mcolors.ListedColormap(s, N=5) assert_sequence_equal(cm1.colors, cm2.colors)
def test_compiling_variable_length(self): pulse = Pulse(kind='Logical', def_1='0.1', def_2='0.5', channel='Ch1_M1') self.root.items = [pulse] self.context.sampling_frequency = 1e8 res, arrays = self.root.compile_sequence() assert_true(res) assert_in(1, arrays) sequence = np.zeros(100, dtype=np.uint8) sequence[1::2] = 2**5 sequence[21:101:2] += 2**6 assert_sequence_equal(arrays[1], bytearray(sequence))
def check_correct(expected, actual): assert expected.viewkeys() <= actual.viewkeys( ), 'Different keys\nexpected\t{}\nactual\t{}'.format( sorted(expected.keys()), sorted(actual.keys())) for k in expected: exp = expected[k] act = actual[k] if hasattr(exp, '__iter__') and not hasattr(exp, 'items'): assert_sequence_equal( exp, act, 'Different on key "{}".\nexpected\t{}\nactual\t{}'.format( k, exp, act)) else: assert exp == act, 'Different on key "{}".\nexpected\t{}\nactual\t{}'.format( k, exp, act) return True
def test_compiling_M1_pulse(self): self.root.time_constrained = True self.root.sequence_duration = '1' pulse = Pulse(kind='Logical', def_1='0.1', def_2='0.5', channel='Ch1_M1') self.root.items = [pulse] res, arrays = self.root.compile_sequence() assert_true(res) assert_in(1, arrays) sequence = np.zeros(2000, dtype=np.uint8) sequence[1::2] = 2**5 sequence[201:1001:2] += 2**6 assert_sequence_equal(arrays[1], bytearray(sequence))
def t(self, s, tp, warn_type=None): fmt = M.FormatString(s) [conv] = fmt assert_is_instance(conv, M.Conversion) assert_equal(conv.type, tp) assert_equal(len(fmt.map_arguments), 0) if tp == 'None': assert_sequence_equal(fmt.seq_arguments, []) else: [arg] = fmt.seq_arguments assert_equal(arg.type, tp) if warn_type is None: assert_equal(len(fmt.warnings), 0) else: [warning] = fmt.warnings assert_is_instance(warning, warn_type)
def t(self, s, tp, warn_type=None, integer=False): fmt = M.FormatString(s) [conv] = fmt assert_is_instance(conv, M.Conversion) assert_equal(conv.type, tp) if tp == 'void': assert_sequence_equal(fmt.arguments, []) else: [[arg]] = fmt.arguments assert_equal(arg.type, tp) if warn_type is None: assert_sequence_equal(fmt.warnings, []) else: [warning] = fmt.warnings assert_is_instance(warning, warn_type) assert_equal(conv.integer, integer)
def test_rowset_asDataFrame__with_ROW_ETAG_column(): query_result = { 'concreteType': 'org.sagebionetworks.repo.model.table.QueryResultBundle', 'maxRowsPerPage': 6990, 'selectColumns': [ {'id': '61770', 'columnType': 'STRING', 'name': 'annotationColumn1'}, {'id': '61771', 'columnType': 'STRING', 'name': 'annotationColumn2'} ], 'queryCount': 1, 'queryResult': { 'concreteType': 'org.sagebionetworks.repo.model.table.QueryResult', 'nextPageToken': 'sometoken', 'queryResults': { 'headers': [ {'id': '61770', 'columnType': 'STRING', 'name': 'annotationColumn1'}, {'id': '61771', 'columnType': 'STRING', 'name': 'annotationColumn2'}], 'concreteType': 'org.sagebionetworks.repo.model.table.RowSet', 'etag': 'DEFAULT', 'tableId': 'syn11363411', 'rows': [{'values': ['initial_value1', 'initial_value2'], 'etag': '7de0f326-9ef7-4fde-9e4a-ac0babca73f6', 'rowId': 123, 'versionNumber':456}] } } } query_result_next_page = {'concreteType': 'org.sagebionetworks.repo.model.table.QueryResult', 'queryResults': { 'etag': 'DEFAULT', 'headers': [ {'id': '61770', 'columnType': 'STRING', 'name': 'annotationColumn1'}, {'id': '61771', 'columnType': 'STRING', 'name': 'annotationColumn2'}], 'rows': [{'values': ['initial_value3', 'initial_value4'], 'etag': '7de0f326-9ef7-4fde-9e4a-ac0babca73f7', 'rowId': 789, 'versionNumber': 101112}], 'tableId': 'syn11363411'}} with patch.object(syn, "_queryTable", return_value=query_result),\ patch.object(syn, "_queryTableNext", return_value=query_result_next_page): table = syn.tableQuery("select something from syn123", resultsAs='rowset') dataframe = table.asDataFrame() assert_not_in("ROW_ETAG", dataframe.columns) expected_indicies = ['123_456_7de0f326-9ef7-4fde-9e4a-ac0babca73f6', '789_101112_7de0f326-9ef7-4fde-9e4a-ac0babca73f7'] assert_sequence_equal(expected_indicies, dataframe.index.values.tolist())
def test_compiling_A_pulse(self): self.root.time_constrained = True self.root.sequence_duration = '1' pulse = Pulse(kind='Analogical', shape=SquareShape(amplitude='1.0'), def_1='0.1', def_2='0.5', channel='Ch1_A') self.root.items = [pulse] res, arrays = self.root.compile_sequence() assert_true(res) assert_in(1, arrays) assert_equal(len(arrays), 1) sequence = np.zeros(2000, dtype=np.uint8) sequence[1::2] = 2**5 sequence[201:1001:2] += 2**4 + 2**3 + 4 + 2 + 1 sequence[200:1000:2] += 255 assert_sequence_equal(arrays[1], bytearray(sequence))
def test_navbase(): """ Tests the NavBase class functionality. """ nb = navutils.NavBase() nb.children = [0, 1, 2, 3] nt.assert_sequence_equal(list(nb), list(nb.children)) nt.assert_equal(len(nb), len(nb.children)) nt.assert_equal(len(nb), 4) nt.assert_equal(nb[0], 0) nt.assert_equal(nb[3], 3) nb.children.pop(0) nt.assert_sequence_equal(list(nb), list(nb.children)) nt.assert_equal(len(nb), len(nb.children)) nt.assert_equal(len(nb), 3) nt.assert_equal(nb[0], 1) nt.assert_equal(nb[2], 3)
def test_dm_cxx(): K = 4 Y = np.array([ ([0, 1, 2, 5],), ([1, 0, 1, 2],), ([0, 2, 9, 9],), ], dtype=[('', np.int, (K,))]) Y_np = np.vstack(y[0] for y in Y) cxx_view = cxx_numpy_dataview(Y) r = rng() defn = model_definition(Y.shape[0], [dm(K)]) prior = {'alphas': [1.] * K} cxx_s = cxx_initialize( defn, cxx_view, r, feature_hps=[prior], assignment=[0] * Y.shape[0]) counts = cxx_s.get_suffstats(0, 0)['counts'] assert_sequence_equal(counts, list(Y_np.sum(axis=0)))
def test_dm_cxx(): K = 4 Y = np.array([ ([0, 1, 2, 5], ), ([1, 0, 1, 2], ), ([0, 2, 9, 9], ), ], dtype=[('', np.int, (K, ))]) Y_np = np.vstack(y[0] for y in Y) cxx_view = cxx_numpy_dataview(Y) r = rng() defn = model_definition(Y.shape[0], [dm(K)]) prior = {'alphas': [1.] * K} cxx_s = cxx_initialize(defn, cxx_view, r, feature_hps=[prior], assignment=[0] * Y.shape[0]) counts = cxx_s.get_suffstats(0, 0)['counts'] assert_sequence_equal(counts, list(Y_np.sum(axis=0)))
def testQueryForm(): eventObj = form.Event.get('testQueryForm') ids = map(lambda x: x.form_id, eventObj.query()) assert_sequence_equal(ids, queryFormIds) ids = map(lambda x: x.form_id, eventObj.query(2, 1)) assert_sequence_equal(ids, queryFormIds[2:4]) ids = map(lambda x: x.form_id, eventObj.query(status = 1)) assert_sequence_equal(ids, queryFormIds[0:2])
def test_tcp_default_and_port_keyword_optional_multiple_ports_and_port_ranges(self): assert_sequence_equal(self.cassandra, RuleParser.parse("7000-7001, 7199,61620-61621 cassandra"))
def t(*args, **kwargs): # Positional arguments are the expected ones, keyword # arguments are passed to db.iterator() kwargs.update(include_value=False) actual = list(db.iterator(**kwargs)) assert_sequence_equal(args, actual)
def test_tcp_default(self): assert_sequence_equal([self.all_tcp], RuleParser.parse("port 0-65535 default"))
def test_address_mask_defaults_to_32(self): assert_sequence_equal([self.single_address], RuleParser.parse("tcp port 0-65535 1.2.3.4"))
def test_manual_remove_element(self): s = self.signal s.add_xray_lines_markers(['Zn_Ka', 'Zn_Kb', 'Zn_La']) s.remove_xray_lines_markers(['Zn_Kb']) nt.assert_sequence_equal(sorted(s._xray_markers.keys()), ['Zn_Ka', 'Zn_La'])
def test_address_with_mask(self): assert_sequence_equal([self.single_address], RuleParser.parse("tcp port 0-65535 1.2.3.4/32"))
def test_tcp_default_and_port_keyword_optional(self): assert_sequence_equal([self.all_tcp], RuleParser.parse("0-65535 default"))
def test_rowset_asDataFrame__with_ROW_ETAG_column(): _try_import_pandas('test_rowset_asDataFrame__with_ROW_ETAG_column') query_result = { 'concreteType': 'org.sagebionetworks.repo.model.table.QueryResultBundle', 'maxRowsPerPage': 6990, 'selectColumns': [{ 'id': '61770', 'columnType': 'STRING', 'name': 'annotationColumn1' }, { 'id': '61771', 'columnType': 'STRING', 'name': 'annotationColumn2' }], 'queryCount': 1, 'queryResult': { 'concreteType': 'org.sagebionetworks.repo.model.table.QueryResult', 'nextPageToken': 'sometoken', 'queryResults': { 'headers': [{ 'id': '61770', 'columnType': 'STRING', 'name': 'annotationColumn1' }, { 'id': '61771', 'columnType': 'STRING', 'name': 'annotationColumn2' }], 'concreteType': 'org.sagebionetworks.repo.model.table.RowSet', 'etag': 'DEFAULT', 'tableId': 'syn11363411', 'rows': [{ 'values': ['initial_value1', 'initial_value2'], 'etag': '7de0f326-9ef7-4fde-9e4a-ac0babca73f6', 'rowId': 123, 'versionNumber': 456 }] } } } query_result_next_page = { 'concreteType': 'org.sagebionetworks.repo.model.table.QueryResult', 'queryResults': { 'etag': 'DEFAULT', 'headers': [{ 'id': '61770', 'columnType': 'STRING', 'name': 'annotationColumn1' }, { 'id': '61771', 'columnType': 'STRING', 'name': 'annotationColumn2' }], 'rows': [{ 'values': ['initial_value3', 'initial_value4'], 'etag': '7de0f326-9ef7-4fde-9e4a-ac0babca73f7', 'rowId': 789, 'versionNumber': 101112 }], 'tableId': 'syn11363411' } } with patch.object(syn, "_queryTable", return_value=query_result),\ patch.object(syn, "_queryTableNext", return_value=query_result_next_page): table = syn.tableQuery("select something from syn123", resultsAs='rowset') dataframe = table.asDataFrame() assert_not_in("ROW_ETAG", dataframe.columns) expected_indicies = [ '123_456_7de0f326-9ef7-4fde-9e4a-ac0babca73f6', '789_101112_7de0f326-9ef7-4fde-9e4a-ac0babca73f7' ] assert_sequence_equal(expected_indicies, dataframe.index.values.tolist())
def t(s): fmt = M.FormatString(s) assert_equal(len(fmt), 1) assert_sequence_equal(fmt.warnings, [])
def check(s, *expected): assert_sequence_equal(parse(s, d), expected)
def test_next_sign_change(): nsc = Moon(2456867.914486644).next_sign_change() assert_equal(jd2iso(nsc), '2014-07-31 16:09:11') assert_sequence_equal(Moon(nsc).position().rel_tuple, ('Libra', 0, 0, 0))
def test_stdin_nicks(self): command = loadscores.Command() command.stdin = StringIO(INPUT) with patch.object(loadscores, 'readlines') as mock_readlines: # Fake readlines to produce nicknames: mock_readlines.return_value = NICKNAMES.splitlines() self.execute(command, nicknames_path='/like/a/file/path') tools.eq_(command.stdout.read(), "Header is:\n\t{}\n".format(HEADER)) tools.eq_(command.stderr.read(), "") tools.assert_sequence_equal(sorted(fulldocs(StateNameVoter.items.all())), [ {'state_lname_fname': 'NH_BULLWINKLE_BORBOR', 'gotv_score': Decimal('-0.009')}, {'state_lname_fname': 'NH_BULLWINKLE_BORIS', 'gotv_score': Decimal('-0.009')}, {'state_lname_fname': 'NH_BULLWINKLE_BORY', 'gotv_score': Decimal('-0.009')}, {'state_lname_fname': 'NH_BEARINGTON_JAY', 'gotv_score': Decimal('-0.1'), 'persuasion_score': Decimal('4.61')}, {'state_lname_fname': 'NH_BEARINGTON_JAMES', 'gotv_score': Decimal('-0.1'), 'persuasion_score': Decimal('4.8')}, {'state_lname_fname': 'NH_BEARINGTON_JOHN', 'gotv_score': Decimal('-0.007'), 'persuasion_score': Decimal('4.61')}, {'state_lname_fname': 'NH_ZIP_JOE', 'persuasion_score': Decimal('0'), 'gotv_score': Decimal('0')}, {'state_lname_fname': 'NH_ZIP_JOSEPH', 'persuasion_score': Decimal('0'), 'gotv_score': Decimal('0')}, {'state_lname_fname': 'MN_STANTON_JANE', 'gotv_score': Decimal('0.003'), 'persuasion_score': Decimal('4.1')}, ]) tools.assert_sequence_equal(sorted(fulldocs(StateCityNameVoter.items.all())), [ {'state_city_lname_fname': 'NH_SEABROOK_BULLWINKLE_BORBOR', 'gotv_score': Decimal('-0.009')}, {'state_city_lname_fname': 'NH_SEABROOK_BULLWINKLE_BORIS', 'gotv_score': Decimal('-0.009')}, {'state_city_lname_fname': 'NH_SEABROOK_BULLWINKLE_BORY', 'gotv_score': Decimal('-0.009')}, {'state_city_lname_fname': 'NH_ST-PAUL_BEARINGTON_JAMES', 'gotv_score': Decimal('-0.1'), 'persuasion_score': Decimal('4.8')}, {'state_city_lname_fname': 'NH_ST-PAUL_BEARINGTON_JAY', 'gotv_score': Decimal('-0.1'), 'persuasion_score': Decimal('4.8')}, {'state_city_lname_fname': 'NH_MILTON_BEARINGTON_JAY', 'gotv_score': Decimal('-0.007'), 'persuasion_score': Decimal('4.61')}, {'state_city_lname_fname': 'NH_MILTON_BEARINGTON_JOHN', 'gotv_score': Decimal('-0.007'), 'persuasion_score': Decimal('4.61')}, {'state_city_lname_fname': 'NH_LEBANON_ZIP_JOE', 'persuasion_score': Decimal('0'), 'gotv_score': Decimal('0')}, {'state_city_lname_fname': 'NH_LEBANON_ZIP_JOSEPH', 'persuasion_score': Decimal('0'), 'gotv_score': Decimal('0')}, {'state_city_lname_fname': 'MN_ST-PAUL_STANTON_JANE', 'gotv_score': Decimal('0.003'), 'persuasion_score': Decimal('4.88')}, {'state_city_lname_fname': 'MN_BLAINE_STANTON_JANE', 'gotv_score': Decimal('0.005'), 'persuasion_score': Decimal('4.1')}, ])